On Wed, 2003-06-18 at 12:43, Hyrum Wright wrote:
> Howdy.
> I'm trying to figure out how to use tr or sed to replace all the newline
> characters in a text stream, as in `cat file | sed ...`
>
> I've tried the following:
> cat file | tr "\012" "\\n"
> cat file | sed -e "{s/\n/\\n/}"
These aren't working because tr only swaps individual characters, you're
trying to turn 1 character into 2. Similarly sed reads its input a line
at a time. Hence the ability to use
's/Hi Mom$/Send money if you want to see your son again./'
I can't think of a good way using just the shell off the top of my head.
awk is mystery to me because by the time I need it I'm usually better
off switching to perl. You might try one of those two. It'd be easy in
perl. In fact, as easy as:
perl -e 'for (`cat file`) { chomp; print $_,"\\n"; }'
--
Stuart Jansen <[EMAIL PROTECTED], AIM:StuartMJansen>
"What hole did you dig that up from?"
-- my roommate commenting on my taste in music
signature.asc
Description: This is a digitally signed message part
____________________ BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________ List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
