I have hundreds of files, named as follows:
RG1-t.txt
RG1-n.txt
RG2-t.txt
RG2-n.txt
etc...
I would like to use GNU parallel to run scripts on them, but I struggle to get the basenames of the files, so RG1, RG2 etc... so that I can run:
ls RG*.txt | parallel "command.sh {basename}-t.txt {basename}-n.txt > {basename}.out"
resulting in the files RG1.out, RG2.out etc. Any ideas?
Use the built-in stripping options:
Dirname (
{/}
) and basename ({%}
) and remove custom suffix ({^suffix}
)
$ echo dir/file_1.txt.gz | parallel --plus echo {//} {/} {%_1.txt.gz}
Get basename, and remove last (
{.}
) or any ({:}
) extension
$ echo dir.d/file.txt.gz | parallel 'echo {.} {:} {/.} {/:}'
This should do what you need:
ls RG*.txt | parallel "command.sh {.}-t.txt {.}-n.txt > {.}.out"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With