Copying a file to multiple other files using a text file as input

Hello,

I have a file called COMPLIST as follows that contains 4 digit numbers.

0002
0003
0010
0013
0015
0016
0022
0023
0024
0025
0027
0030
0031
0032
0033
0035
0038
0041
0044
0046
0051
0052
0053
0054
0056
0057
0058
0062
0066
0068
0076

I want to use a loop to copy a file called comp to create new files using the same 4 digit files names from the COMPLIST text file..if that makes sense..

I don't fancy doing 100's of cp commands (cp comp 0002 ;cp comp 0003) etc..

I can then manage things easier using my COMPLIST instead of doing manual copies.

Whats the best way to do it ?

Hello sph90457,

Kindly use code tags as per forum rules for commands/codes which you are using in your posts as per forum rules.
Following may help you in same.

awk '{print "cp " FILENAME  OFS $1}' comp

Above command will only print the commands, if happy with results then use following command for same.

awk '{print "cp " FILENAME  OFS $1}' comp | sh

Thnaks,
R. Singh

Another way with xargs which might be wastefully using cat too, but it works:-

cat COMPFILE | xargs -tn1 cp comp

Robin

man tee

But be warned, if tee fails on a write, it merrily continues on its way. I found that one out the hard way...