Database Reference
In-Depth Information
If you use parallel as often as us then you may want to create an
alias (e.g., p ) by adding alias p=parallel to your ~/.bashrc . (In
this chapter, we'll just use parallel for clarity.)
Specifying Input
The most important argument to GNU Parallel is the command that you would like
to run for every input. The question is: where should the input item be inserted in the
command line? If you do not specify anything, the input item will be appended to the
command. While this is usually what you want, it's best to be explicit about where
the input item should be inserted in the command using one or more placeholders.
There are many ways to provide input to GNU Parallel. We prefer
piping the input (as we do throughout this chapter) because that is
generally applicable and allows us to construct a pipeline from left
to right. Consult the man page of parallel to read about other
ways to provide input.
In most cases, you probably want to use the entire input item as it is. For this, you
only need one placeholder. You specify the placeholder with two curly braces ( {} ):
$ seq 5 | parallel echo {}
When the input item is a file, there are a couple of special placeholders you can use to
modify the filename. For example, with {./} , only the basename of the filename will
be used.
If the input line has multiple parts separated by a delimiter, you can add numbers to
the placeholders. For example:
$ < input.csv parallel -C, "mv {1} {2}"
Here, you can apply the same placeholder modifiers. It's also possible to reuse the
same input item. If the input to parallel is a CSV file with a header, then you can
use the column names as placeholders:
$ < input.csv parallel -C, --header : "invite {name} {email}"
Sometimes you just want to run the same command without any changing inputs.
This is also possible in parallel . We just have to specify the -N0 option and give as
input as many lines as you want to execute:
$ seq 5 | parallel -N0 "echo The command line rules"
The command line rules
The command line rules
The command line rules
Search WWH ::




Custom Search