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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cat multiple files but append new line between each file

Status
Not open for further replies.

new2unix

Programmer
Feb 5, 2001
143
US
Hi,

I have multiple files, say, test1.dat, test2.dat, etc. Each file has only one record. I tried:

cat test*.dat > final.dat

The records from each file were combined into one line instead of separate lines in the final.dat file.

How do I combined the record from each file while appending new line after each record?

Thanks,

Mike
 
Hi

I know no way to do it with [tt]cat[/tt], so I would use AWK :
Code:
awk 'FNR==1&&NR!=1{print""}1' test*.dat > final.dat
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Alternatively you could take a look at [tt]paste[/tt], especially if yours support [tt]-s[/tt] ( [tt]--serial[/tt] ) and [tt]-d[/tt] ( [tt]--delimiters[/tt] ) switches.


Feherke.
 
Maybe
Code:
for i in test*.dat ; do cat $i ; echo "" ; done > final.dat


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top