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


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying a file to multiple other files using a text file as input
# 1  
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.
Code:
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 ?

Last edited by rbatte1; 03-05-2015 at 02:01 PM.. Reason: Added CODE tags
# 2  
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.
Code:
awk '{print "cp " FILENAME  OFS $1}' comp

Above command will only print the commands, if happy with results then use following command for same.
Code:
awk '{print "cp " FILENAME  OFS $1}' comp | sh

Thnaks,
R. Singh
# 3  
Another way with xargs which might be wastefully using cat too, but it works:-
Code:
cat COMPFILE | xargs -tn1 cp comp


Robin
# 4  
Code:
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...
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #572
Difficulty: Easy
For most programming languages, array indices start at zero. This is known as zero-indexing.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying multiple files and appending time stamp before file extension

Hi, I have multiple files that read: Asa.txt Bad.txt Gnu.txt And I want to rename them using awk to Asa_ddmmyytt.txt and so on ... If there is a single command or more efficient executable please share! Thanks! (4 Replies)
Discussion started by: Jesshelle David
4 Replies

2. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

I have a environment property file which contains: Input file: value1 = url1 value2 = url2 value3 = url3 and so on. I need to search all *.xml files under directory for value1 and replace it with url1. Same thing I have to do for all values mentioned in input file. I need script in unix bash... (7 Replies)
Discussion started by: Shamkamde
7 Replies

3. Shell Programming and Scripting

Split: File into multiple and keeping the same 3 lines from input into all output files

The following code will split the infile into multiple files. However, I need it to insert the same first 3 lines from the original input file into each splitted file. How do I modify my script below to do so: print -n "Enter file name to split? " ; read infile if then echo "Invalid file... (4 Replies)
Discussion started by: mrn6430
4 Replies

4. UNIX for Dummies Questions & Answers

Changing text in multiple files, but with different text for each file

Hello, I have a situation where I want to change a line of text in multiple files, but the problem is that I want to change the text to something unique for each file. For example, let's say I have five files named bob.txt, joe.txt, john.txt, tom.txt, and zach.txt. Each of these files has a... (5 Replies)
Discussion started by: Scatterbrain26
5 Replies

5. Shell Programming and Scripting

How to ftp multiple files by taking the file name from a input file.

Hi, I'm working on a script which has to copy multiple files from one server to another server. The list of files that are to be copied is present in a file say input.txt. vi input.txt abc.c welcome.c new.c welcome1.c for ftp'ing a single file say 'new.c' the following code... (2 Replies)
Discussion started by: i.srini89
2 Replies

6. Shell Programming and Scripting

Split a file into multiple files based on the input pattern

I have a file with lines something like. ...... 123_start ...... ....... 123_end .... ..... 456_start ...... ..... 456_end .... ..... 789_start .... .... 789_end (6 Replies)
Discussion started by: abinash
6 Replies

7. Shell Programming and Scripting

Search & Replace in Multiple Files by reading a input file

Hi, I have a folder which contains multiple config.xml files and one input file, Please see the below format. Config Files format looks like :- Code: <application name="SAMPLE-ARCHIVE"> <NVPairs name="Global Variables"> <NameValuePair> ... (0 Replies)
Discussion started by: haiksuresh
0 Replies

8. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

9. Shell Programming and Scripting

building output file from multiple input files

Hi there, I am trying to figure out a way to combine multiple sources with different data on a single file, and I am trying to find the best way to do it. I have multiple files, let's say A, B, C and D. A has a field in common with B, B has a field in common with C, and C has a field in... (2 Replies)
Discussion started by: ppucci
2 Replies

10. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies

Featured Tech Videos