質問

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.

役に立ちましたか?

解決 2

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

他のヒント

Use a loop to achieve this:

for line in $(cat names) ; do cp file.pdf dir/${line}_file.pdf; done
 for fl in `cat names.txt`
  do 
   cp file.pdf dir/${fl}_file.pdf
  done 

hope this helps !!

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top