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

Join all lines in a file 2

Status
Not open for further replies.

MikeAJ

Programmer
May 22, 2002
108
US
I'm trying to join all lines in a file so there is only one line remaining. Here is what I've tried:

Code:
sed '$!N;s/\n//g' /files/multiline.txt > /files/singleline.txt

This seems like it would work, but it joins line 1 and 2 and then lines 3 and 4, but it doesn't join the new line 1 with the new line 2.

Is there a better way other than sed to do this?

Thanks!
 
sorry, it was printf not print

awk '{ printf $0 }' file.txt > newfile.txt

Chacal, Inc.
 
How about...
Code:
tr -d '\n' < file.txt > newfile.txt
Hope this helps.
 
Thanks to both of you for the quick response! Both methods work perfectly!
 
awk '{ printf $0 }' file.txt > newfile.txt
This will fail with the first line that contains "%s", "%d", etc. Correct is
Code:
awk '{printf "%s",$0}'
or
Code:
awk 'BEGIN{ORS=""}1'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top