Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging files in Unix

Status
Not open for further replies.

hugheskbh

Programmer
Dec 18, 2002
37
US
Can someone tell how would I merge 3 different files: a header file with one record, a detail file with numerous records, and a trailer file with a trailer record. I need to merge these file into one with the header record, detail record and trailer record.

If anyone knows how to do this, please let me know.

Thanks
 
Hello hugheskbh,

I think you can achieve it like this:

cat detailfile>>headerfile;cat trailerfile>>headerfile

I'm sure you can even do it in one step:

cat detailfile trailerfile>>headerfile

Anyway, afterwards headerfile will contain all 3 files. To preserve the sourcefiles try:

cat headerfile detailfile trailerfile>newfile

Kind Regards
Stephan



 
Does anyone know if one can merge 3 files based on certain criteria. IE where file name starts with 9 digit code, merge those files and create new file. Is this possible?
 
Wildcards used for filenames:-

* = any number of characters
? = any single character
[0-9] = any single character in the ascii range 0 thru 9

Merge all files where file name starts with 9 digit code....

cat [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]* > newfile


 
and would i have to specify all file names or will the cat [000012_AP]* > new file do it for all files that start with 000012_AP?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top