diff options
| author | Jan T <jan@jantuomi.fi> | 2025-11-13 11:31:30 +0000 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-11-13 13:34:38 +0200 |
| commit | 3df80b5afbebbf3af63b49fe98a3faecd2b68439 (patch) | |
| tree | 3db37a25de23b7a6b21b3df261b84dc1359c1555 /README.md | |
Initial commit
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..790d3e5 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# pipetools + +A collection of familiar and intuitive shell tools for processing text data in a pipeline. The only dependencies are POSIX utilities such as `tr` that should be available on any POSIX-compliant system. + +## Examples + +```sh +echo foo bar baz | words +# Output: +foo +bar +baz +``` + +```sh +echo foo bar baz | words | map '$IDX $ELEM' | filter '$IDX -gt 0' +# Output: +1 bar +2 baz +``` + +```sh +echo foo bar baz | words | map '$IDX $ELEM' | map '$IDX $(( $X0 + 10 )) $X1' +# Output: +0 10 foo +1 11 bar +2 12 baz +``` + +```sh +echo foo bar baz | words | map '$(( $IDX + 1 ))' | reduce 1 '$(( $ACC * $ELEM ))' +# Output: +6 +``` + +The tools all follow the same conventions: + +- Input is line-based (newline-separated). You can use `words` to convert whitespace to newlines. +- `$IDX` is the index of the element in the input stream. +- `$ELEM` is the element itself. +- `$X0`, `$X1`, etc. are the whitespace separated words in the current element (think columns in a table). +- `$ACC` is the accumulator for the reduce operation. + +The `$(( $X0 + $X1 ))` syntax is called arithmetic expansion, which allows for basic arithmetic operations within a shell script. + +## Installation + +Copy the contents of the `tools` directory to a directory in your PATH, or run the `install.sh` script to create symlinks automatically to your selected target directory. + +## Author + +Jan Tuomi <<jan@jantuomi.fi>> |
