Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basename in GNU Parallel

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?

like image 415
ATpoint Avatar asked Aug 23 '17 15:08

ATpoint


1 Answers

Use the built-in stripping options:

  1. Dirname ({/}) and basename ({%}) and remove custom suffix ({^suffix})

    $ echo dir/file_1.txt.gz | parallel --plus echo {//} {/} {%_1.txt.gz}

  2. 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"
like image 66
jaygooby Avatar answered Oct 18 '22 07:10

jaygooby