| Parallelize STDIN Now, let's imagine we have 1 large file (e.g. 30 GB) that needs to be converted, line by line. Say we have a script, convert.sh, that does this <task>. We can pipe contents of this file to stdin for parallel to take in and work with in chunks such as where <stdin> can originate from anything such as cat <file>. As a reproducible example, our task will be nl -n rz. Take any file, mine will be data.bz2, and pass it to <stdin> The above example takes <stdin> from bzcat data.bz2 | nl, where I included nl just as a proof of concept that the final output output.gz will be saved in the order it was received. Then, parallel divides the <stdin> into chunks of size 10 MB, and for each chunk it passes it through nl -n rz where it just appends a numbers rightly justified (see nl --help for further details). The options --pipe tells parallel to split <stdin> into multiple jobs and -- block specifies the size of the blocks. The option -k specifies that ordering must be maintained. Your final output should look something like My original file had 552,413 lines. The first column represents the parallel jobs, and the second column represents the original line numbering that was passed to parallel in chunks. You should notice that the order in the second column (and rest of the file) is maintained. Syntax - parallel [options]command [arguments]] < list_of_arguments >
Parameters | Option | Description | -j n | Run n jobs in parallel | -k | Keep same order | -X | Multiple arguments with context replace | --colsep regexp | Split input on regexp for positional replacements | {} {.} {/} {/.} {#} | Replacement strings | {3} {3.} {3/} {3/.} | Positional replacement strings | -S sshlogin | Example: [email protected] | --trc {}.bar | Shorthand for --transfer --return {}.bar --cleanup | --onall | Run the given command with argument on all sshlogins | --nonall | Run the given command with no arguments on all sshlogins | --pipe | Split stdin (standard input) to multiple jobs. | --recend str | Record end separator for --pipe. | --recstart str | Record start separator for --pipe. |
|