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

Replace newline characters with space, joining all lines 1

Status
Not open for further replies.

hallux

Programmer
Feb 25, 2003
133
US
Hi,
I would like to use sed to replace all newline characters with spaces, thereby joining all lines into one.

Example:
Car
Bike
Scooter

Would become "Car Bike Scooter"

I tried using "\n", but it didn't work.
-Brent
 
tr '\n' ' ' < myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks vgersh99, that's exactly what I needed.
I also found a 'tr' command to get rid of more unprintable characters:

tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' < filein > fileout

Source: &quot;Very short guide to sed, tr, cut and od&quot;
Author: Sakari Mattila

I might as well share a little more:)
To see all characters in a file or output, use 'od'.

$ echo &quot;hello world&quot; | od -x
0000000 6865 6c6c 6f20 776f 726c 640a
0000014

Notice that h is 68, e is 65 , l is 6c, o is 6f, etc

$ echo &quot;hello world&quot; | od -c
0000000 h e l l o w o r l d \n
0000014

$ echo &quot;hello\t world&quot; | od -c
0000000 h e l l o \t w o r l d \n
0000015

-Brent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top