Crates.io | imex |
lib.rs | imex |
version | 0.2.1 |
source | src |
created_at | 2020-08-10 01:53:11.246798 |
updated_at | 2020-09-29 06:39:00.286744 |
description | A library/CLI for merging multiple iterators/files into one, with the optional use of an IMEx, or Iterator-Merging-Expression, for controlling the merge. |
homepage | |
repository | https://github.com/Trouv/imex |
max_upload_size | |
id | 274881 |
size | 57,139 |
A library/CLI for merging multiple iterators/files into one, with the optional use of an IMEx, or Iterator-Merging-Expression, for controlling the merge.
IMEx is based off of RegEx. A quick reference of IMEx syntax:
()
- defines a group*
- repeats the previous digit/group until the relevant iterator(s) are
exhausted{x}
- repeats the previous digit/group x
times, or until the relevant
iterator(s) are exhausted."0110"
on two iterators: results in a merged iterator that starts
with the first item of the first iterator, then the first two items of the
second iterator, then the second item of the first iterator
"(01)*"
on two iterators: results in a merged iterator whose elements
alternate between the elements of the input iterators until they are both
exhausted.
"(012){4}(122)*"
on three iterators: results in a merged iterator whose
elements rotate through the elements of the input iterators 4 times, then picks
an element of the second iterator followed by two elements of the third
repeatedly until they are both exhausted.
Using the CLI tool allows you to merge multiple files line-by-line. To respect the Unix philosophy, stdin can also be merged with other files, and the result is printed to the screen.
Files are provided as positional arguments, and an IMEx can be provided using
the -i
option.
The digits of the IMEx will refer to one of the files you provide in the order
you provide them, 0-indexed.
The filename -
is reserved for stdin.
So, the following command will merge the output of the ls
command with two
other files, taking 10 lines from stdin and then one from each of the files
until they're all exhausted, then output it to a file called out.txt
:
$ ls | imex - file1.txt file2.txt -i "(0{10}12)*" > out.txt
If you are a rust developer, you can install IMEx through cargo:
$ cargo install imex
Currently, imex doesn't exist in any other package manager.
Using the IMEx crate in your code primarily gives you access to some new functions on iterators that merge and return iterators. These can all be used in a typical iterator processing chain. Details on usage and implementation can be read in the crate's documentation.
There is one main feature planned for imex:
Licensed under either of Apache License, Version 2.0 or MIT license at your option.