Replacement Strings
A replacement string is where an input
goes inside your command. {} is the
input itself; the others cut it into the
pieces file work usually needs. All of
these were run for real in transcript
t02, over two inputs chosen to show the
cuts:
$ parallel echo '{} :: {/} :: {//} :: {.} :: {/.}' ::: samples/north/notes-01.txt archive/backup.tar.gz
samples/north/notes-01.txt :: notes-01.txt :: samples/north :: samples/north/notes-01 :: notes-01
archive/backup.tar.gz :: backup.tar.gz :: archive :: archive/backup.tar :: backup.tar
| String | Meaning | samples/north/notes-01.txt becomes |
|---|---|---|
{} |
the input, whole | samples/north/notes-01.txt |
{/} |
basename — directory removed | notes-01.txt |
{//} |
dirname — only the directory | samples/north |
{.} |
extension removed | samples/north/notes-01 |
{/.} |
basename, extension removed | notes-01 |
Two details the table makes visible:
- Only the last extension goes.
archive/backup.tar.gzunder{.}isarchive/backup.tar, notarchive/backup. Parallel removes one suffix, which is what you want for.tar.gzfiles most of the time. - The pieces compose. Building an
output name is usually
{/.}for the stem plus a new ending of your own:convert {} {.}.png, or with a redirection,tr a-z A-Z < {} > {/.}.upper.
Positional strings: {1} {2} …
With more than one input source
(chapter 7), {1} is the input from
the first source, {2} from the
second, and the cutting forms follow:
{1/} is the basename of the first,
{2.} the second without extension.
$ parallel -k echo '{1} goes with {2}: {1/} + {2.}' ::: red blue ::: report.txt data.csv
red goes with report.txt: red + report
red goes with data.csv: red + data
blue goes with report.txt: blue + report
blue goes with data.csv: blue + data
Two more worth knowing
{#}— the job's sequence number, the same number the job log uses. Handy for naming temporary outputs that must not collide:tmp-{#}.{= … =}— a Perl expression evaluated per input, for transformations the five cutters can't do (changing case, arithmetic). It is powerful and easy to abuse; the manual's examples are the place to learn it, and most everyday work never needs it.
The quoting rule
Parallel quotes each replacement for
the shell, so a filename containing
spaces or an apostrophe arrives at your
command intact — one argument, not
several. The command template itself
is a shell command line, though: pipes,
&& and redirections you write in it
are real shell syntax. That is a
feature (chapter 10 uses it) and the
source of the classic beginner's bug
of putting an unquoted | or > in a
template and watching it act on the
whole run instead of per job. Chapter
14 has the symptom and the fix.