Reputation: 31
Given a PDF file (eg. file.pdf) and a text file (eg. names.txt) containing a list of names (eg. joe, fred, sam) how can I copy the pdf file to a new folder (eg. dir) multiple times so that the new files include the names from the text file.
ie
file.pdf
copied to
dir/joe_file.pdf
dir/fred_file.pdf
dir/sam_file.pdf
I've tried using xarg with no success
cat names.txt | xargs cp file.pdf dir/{}_file.pdf
Any ideas please?
Using OSX to do this.
Upvotes: 2
Views: 1506
Reputation: 31
In the end I used the following which works a treat. Thanks for your help!
cat names.txt | xargs -I{} cp file.pdf "{}"\ file.pdf
Upvotes: 1
Reputation: 33725
Use GNU Parallel:
parallel cp file.pdf dir/{}_file.pdf :::: names
If you need to do it for a bunch of pdf files:
parallel cp {2} dir/{1}_{2} :::: names ::: *.pdf
Learn more about GNU Parallel: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
10 second installation:
wget pi.dk/3 -qO - | sh -x
Upvotes: 0
Reputation: 17562
for fl in `cat names.txt`
do
cp file.pdf dir/${fl}_file.pdf
done
hope this helps !!
Upvotes: 0
Reputation: 2527
Use a loop to achieve this:
for line in $(cat names) ; do cp file.pdf dir/${line}_file.pdf; done
Upvotes: 1