Create a file based on multiple files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Create a file based on multiple files
# 1  
Old 04-29-2010
Create a file based on multiple files

Hey everyone.

I am trying to figure out a way to create a file that will be renamed based off of one of multiple files. For example, if I have 3 files (cat.ctl, dog.ctl, and bird.ctl) that gets placed on to an ftp site I want to create a single file called new.cat.ctl, new.dog.ctl, etc for each but if there was a file called falcon.ctl it would not create a "new" file unless it was added to the list of names it was looking for. Inside the file, it will basically be a copy of the old file. I have an if statement in mind but I am still fairly new to Unix. I have tried to explain it how I want to do it but I am just not sure. I would appreciate any help the forum can give.
# 2  
Old 04-29-2010
in your local ftp server directory
Code:
find /path/to/ftp/directory -name '*.ctl' |
while read fname
do
if [[! -f   /path/to/ftp/directory/new.$(basename $fname) ]] ; then
     mv ${fname}  /path/to/ftp/directory/new.$(basename $fname)
fi
done

Is that what you meant? this only creates a "new" when a "new" does not already exist.
# 3  
Old 04-29-2010
Something like this may be more elegant than an if/then/else for each file.
Code:
while read FILENAME
do
        get-from-ftp "${FILENAME}" > "${FILENAME}.out" || echo "Couldn't retrieve ${FILENAME} into ${FILENAME}.out"
done < list-of-files

# 4  
Old 04-29-2010
Quote:
Originally Posted by jim mcnamara
in your local ftp server directory
Code:
find /path/to/ftp/directory -name '*.ctl' |
while read fname
do
if [[! -f   /path/to/ftp/directory/new.$(basename $fname) ]] ; then
     mv ${fname}  /path/to/ftp/directory/new.$(basename $fname)
fi
done

Is that what you meant? this only creates a "new" when a "new" does not already exist.

This is similar to what I have in mind. I know that if I use a wild card it would pickup everything with a .ctl but if I set it up with something like find /path/to/ftp/directory -name 'c*.ctl' then that would limit what files get moved. I will try this out.

Thanks Jim.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create file based on data from two other files

I have looked through several threads regarding merging files with awk and attempted using join however have been unsuccessful likely as I do not fully understand awk. What I am attempting is to take a csv file which could be between 1 and 15,000 lines with 5 colums and another csv file that will... (4 Replies)
Discussion started by: cdubu2
4 Replies

2. Shell Programming and Scripting

Split a single file into multiple files based on a value.

Hi All, I have the sales_data.csv file in the directory as below. SDDCCR; SOM ; MD6546474777 ;05-JAN-16 ABC ; KIRAN ; CB789 ;04-JAN-16 ABC ; RAMANA; KS566767477747 ;06-JAN-16 ABC ; KAMESH; A33535335 ;04-JAN-16 SDDCCR; DINESH; GD6674474747 ;08-JAN-16... (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies

3. Shell Programming and Scripting

Create multiple files from single file based on row separator

Hello , Can anyone please help me to solve the below - Input.txt source table abc col1 char col2 number source table bcd col1 date col2 char output should be 2 files based on the row separator "source table" abc.txt col1 char (6 Replies)
Discussion started by: Pratik4891
6 Replies

4. Shell Programming and Scripting

awk Parse And Create Multiple Files Based on Field Value

Hello: I am working parsing a large input file which will be broken down into multiples based on the second field in the file, in this case: STORE. The idea is to create each file with the corresponding store number, for example: Report_$STORENUM_$DATETIMESTAMP , and obtaining the... (7 Replies)
Discussion started by: ec012
7 Replies

5. Shell Programming and Scripting

Comparing Select Columns from two CSV files in UNIX and create a third file based on comparision

Hi , I want to compare first 3 columns of File A and File B and create a new file File C which will have all rows from File B and will include rows that are present in File A and not in File B based on First 3 column comparison. Thanks in advance for your help. File A A,B,C,45,46... (2 Replies)
Discussion started by: ady_koolz
2 Replies

6. Shell Programming and Scripting

How to create multiple files from one file?

Hi everyone! I usually get large files with different groups of entries; for example, each line starts with A, B, C, D, or E. Is there a way to separate all these entries and then write them in 5 different files with one awk program? Thank you! (4 Replies)
Discussion started by: Avro1986
4 Replies

7. Shell Programming and Scripting

create separate files from one excel file with multiple sheets

Hi, I have one requirement, create separate files (".csv") from one excel file(xlsx) with multiple sheets. These ".csv" files are my source files. So anybody please suggest me the process. Thanks in Advance. Regards, Harris (3 Replies)
Discussion started by: harris
3 Replies

8. Shell Programming and Scripting

How to split file into multiple files using awk based on 1 field in the file?

Good day all I need some helps, say that I have data like below, each field separated by a tab DATE NAME ADDRESS 15/7/2012 LX a.b.c 15/7/2012 LX1 a.b.c 16/7/2012 AB a.b.c 16/7/2012 AB2 a.b.c 15/7/2012 LX2 a.b.c... (2 Replies)
Discussion started by: alexyyw
2 Replies

9. Shell Programming and Scripting

Create files based on second column of a file

Hi All, I have a file which looks like this: 234422 1 .00222 323232 1 3232 32323 1 0.00222 1234 2 1211 2332 2 0.9 233 3 0.883 123 3 45 As you can see, the second column of the file is already sorted which I did using sort command. Now, I want to create files based on the second... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

10. Shell Programming and Scripting

create diffrent files based on other file and parameters list

I would like ot create shell script/ bash to create diffrent files based on a file and parameters list. Here is the detail example: I have a textfile and four static parameter files (having ‘?'). mainfile.txt has below records (this count may be more than 50) A200001 A200101 B200001... (9 Replies)
Discussion started by: raghav525
9 Replies
Login or Register to Ask a Question