2

I have a simple script that I want to copy and rename files, in files.lst based on a list of names in names.lst

**name.lst**
100GV200.vcf
150GV200.vcf
14300GV200.vcf

**file.lst**
file1.txt
file2.txt
file3.txt

My script so far looks like this:

parallel --link -k "cp {} {}" :::: file.lst :::: name.lst

Unfortunately I get back:

 cp: target `100GV200.vcf` is not a directory

When I run a single cp command in the terminal it works perfectly

cp file1.txt 100GV200.vcf

Where am I going wrong in understanding how GNU parallel reads in arguments?

1
  • 1
    Always try --dry-run if you do not understand what GNU Parallel is doing.
    – Ole Tange
    Feb 25, 2019 at 22:28

3 Answers 3

2

Don't bother with parallel's deranged interface; for file names without special characters you can just go for

paste file.lst name.lst | xargs -n2 echo mv
1

Use {1} and {2} notation:

parallel --link -k cp {1} {2} :::: file.lst :::: name.lst

Works for me, it will work with the quotes as well

parallel --link -k "cp {1} {2}" :::: file.lst :::: name.lst

To get it to work with {}, you would have had to do something like this:

parallel --link -k "cp {}" :::: file.lst :::: name.lst

Because parallel will automatically append the line of the two files.

2
  • Works perfectly. Why does {1} and {2} work but just empty {} not? I thought it would pull 1 argument from file.lst and the other from name.lst
    – AMB
    Feb 9, 2019 at 1:36
  • If you don't specify which input is suppose to be used for the copy, parallel append, for example, if you remove the file 100GV200.vcf and you do this: mv file1.txt 100GV200.vcf file1.txt 100GV200.vcf, you will get the error you were getting. By telling parallel what line you want to go where, you get the move command as intended.
    – NiteRain
    Feb 9, 2019 at 1:50
0

I have used below command to achieve the same

paste file.lst name.lst|  awk '{print "cp" " " $1 " " $2}'|sh

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .