removing end of line mark with sed
Randal Schwartz
merlyn at iwarp.intel.com
Mon Aug 20 09:43:27 AEST 1990
In article <1990Aug19.194911.16628 at fs-1.iastate.edu>, spam at hobbes (Begley Michael L) writes:
| Here's a simple one...
| How do I remove the end of line marker from a stream? for example,
| if I have a stream that esentially looks like:
| 1
| 2
| 3
| how do I make it into:
| 1 2 3
|
| I tried sed 's/\n//' but that didn't work. Thanks.
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
tr '\012' ' '
instead of sed. If you really need the trailing newline, and you have
a shell with a builtin echo, try:
...some_command |
some_command_that_produces_those_lines |
while read x
do echo -n "$x "
done
echo ""
or
echo `some_command_that_produces_those_lines`
depending on how you get your data. The first one is *really*
expensive if you don't have a builtin echo, but the second one isn't
bad.
Obligatory Perl reference:
perl -pe 's/\n/ / unless eof;'
Just another (former) sed user,
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
More information about the Comp.unix.questions
mailing list