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!

Line feeds ....

Status
Not open for further replies.

dbeez

Technical User
Aug 15, 2005
71
KR
Hi,

I have a simple text file that is stacked like this

item1
item2
item3

I want it to be stacked like this

item1,item2,item3

But when I use

sed -e 's/\/r/,/g'

or any variants thereof, I still see the original text in pico ???

What am I doing wrong ??

Thanks
 
Hi feherke,

I'm trying to learn something about sed from your example (I've only really used it for search-and-destroy in the past) but can't get it to work on Solaris 9:

[tt]$ ls | sed -n '1h;1!H;${g;y/\n/,/;p}'
sed: command garbled: 1h;1!H;${g;y/\n/,/;p}
$[/tt]

...or on Linux (sed 3.0.2 or 4.0.7):

[tt]$ ls | sed -n '1h;1!H;${g;y/\n/,/;p}'
sed: -e expression #1, char 18: strings for y command are different lengths
$[/tt]

What I'm usually more intersted in is adding line feeds, so I would be interested in your solution to that as well.

Annihilannic.
 
sed -n '1h;1!H;${[highlight];[/highlight]g;y/\n/,/;p[highlight];[/highlight]}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

I use GNU [tt]sed[/tt] version 4.1.2. You are right, with version 3.02.80 the [tt]y///[/tt] command seems to not work with metacharacters so use [tt]s///[/tt] :
Code:
sed -n '1h;1!H;${g;s/\n/,/g;p}'
Regarding the problem on Solaris, I think will remain an eternal mistery for me. Appearantly that [tt]sed[/tt] is unable to group commands with braces.

Feherke.
 
Thanks PHV, so the block brackets need to appear as separate sed commands?

That fixes it for Solaris sed, but not Linux:

[tt]$ ls | sed -n '1h;1!H;${;g;y/\n/,/;p;}'
sed: -e expression #1, char 19: strings for y command are different lengths
$[/tt]

However this did work for me (^J entered using Ctrl-V, Ctrl-J in vi-editing mode):

[tt]$ ls | sed -n '1h;1!H;${;g;y/\^J/,/;p;}'[/tt]

And so did this:

[tt]$ ls | sed -n '1h;1!H;${;g;y/\
/,/;p;}'[/tt]

And to answer my other question, this changed the output back again:

[tt]$ ls | sed -n '1h;1!H;${;g;y/\^J/,/;p;}' | sed 'y/,/\^J/'[/tt]

Annihilannic.
 
and there is always are old friend xargs:

Code:
cat myitemfile|xargs echo|sed 's/ /,/g'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top