1828225 Members
3564 Online
109975 Solutions
New Discussion

sed help?

 
SOLVED
Go to solution
Rick Garland
Honored Contributor

sed help?

Hi all

Working with a file that looks like so;
item1,
item2,
item3,
...

Would like to have it on 1 line so it likes like;
item1,item2,item3, ...

Trying to do with sed but not having much luck.
Any help?

Many thanks!
3 REPLIES 3
Pete Randall
Outstanding Contributor
Solution

Re: sed help?

Rick,

I don't think this is exactly what you're looking for, but it might be a start:

# join pairs of lines side-by-side (like "paste")
sed 'N;s/\n/ /'

From "Handy One-liners for SED" (attached).


Pete

Pete
Rick Garland
Honored Contributor

Re: sed help?

Many thanks!
James R. Ferguson
Acclaimed Contributor

Re: sed help?

Hi Rick:

Using 'tr' is an inexpensive (resource-wise) way to affect this transformation:

# echo "a,\nb,\nc,\nd,\ne"|tr -s "\012" " "

...or if you want to eliminate the extra blank field seperator:

# echo "a,\nb,\nc,\nd,\ne"|tr -s "\012" " "|tr -d " "

Regards!

...JRF...