Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I have tons of books, have book marked tons of tutorials, which have helped, but this forum has answered those "impossible to find" solutions. I am thrilled with this site..."

Geography

Where in the world do Tek-Tips members come from?

cat multiple files but append new line between each file

new2unix (Programmer)
10 Jun 11 11:05
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  
feherke (Programmer)
10 Jun 11 12:03
Hi

I know no way to do it with cat, so I would use AWK :

CODE

awk 'FNR==1&&NR!=1{print""}1' test*.dat > final.dat
Tested with gawk and mawk.

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

Feherke.
http://free.rootshell.be/~feherke/

Salem (Programmer)
10 Jun 11 13:01
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close