removing end of line mark with sed

Joe Hamlin hamlin at blackbird.afit.af.mil
Mon Aug 20 14:11:01 AEST 1990


merlyn at iwarp.intel.com (Randal Schwartz) writes:

>In article <1990Aug19.194911.16628 at fs-1.iastate.edu>, spam at hobbes (Begley Michael L) writes:
>| [How to turn]:
>| 1
>| 2
>| 3
>| into:
>| 1   2   3

>I horsed around with the 'N' command in sed, thinking I could make it
>do that, and figured out that I had lost the sed touch.  (Somebody
>will most certainly post the proper way to do it.)  Try

Don't know about "proper", but this seems to work:

sed -n -e '1{;h;$p;b' -e '}' -e 'H;$x;$s/\n/ /gp'

Seems a bit ugly, though.  It's not absolutely clear from the
problem, how many spaces/tabs are wanted as separator(s), or
whether or not a trailing newline is required.  Add spaces to
taste.

>tr '\012' ' '

>instead of sed.  If you really need the trailing newline, and you have
>a shell with a builtin echo, try:

>[Randal's echo script]

or:
(tr '\012' ' '; echo)

or:
>echo `some_command_that_produces_those_lines`

Both the tr and single line echo solutions are limited to a single
space separator.

>perl -pe 's/\n/ / unless eof;'
It's even readable. :-)

And in awk:

awk '{printf "%s ", $0} END {print}'
-- 
Joe Hamlin    <hamlin at blackbird.afit.af.mil>



More information about the Comp.unix.questions mailing list