Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jun 2002 09:16:06 -0400
From:      Rob Ellis <rob@web.ca>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: OT: using sed to insert \n at command line
Message-ID:  <20020618131606.GA18107@web.ca>
In-Reply-To: <20020618065319.GA68146@happy-idiot-talk.infracaninophi>
References:  <5.1.1.6.0.20020618161418.020a7780@wheresmymailserver.com> <20020618065319.GA68146@happy-idiot-talk.infracaninophi>

next in thread | previous in thread | raw e-mail | index | archive | help
with tcsh, you need two backslashes before the newline:

> echo "abc xyz" | sed 's/ /\\
? /'
abc
xyz

- rob

> On Tue, Jun 18, 2002 at 04:16:18PM +1000, Jacob Rhoden wrote:
> > I've done some searching online and I cant work out how to do this, and I 
> > was wondering if any of you guys do? This is what I am doing, and when I 
> > try to insert a \n it doesn't work either way:
> > 
> >   input | sed 's/a string/\n/g' | output
> >   input | sed 's/a string/\\n/g' | output
> > 
> > what is the correct way from the command prompt? Thanks for any help . .
> 
> You have to insert a literal newline character into the sed expression
> preceded by a backslash:
> 
> $ echo "bibble babble" | sed -e 's/ /\
> > /g'
> bibble
> babble
> 
> Your ability to do this successfully will be a function of the shell
> you're using.  It works fine with /bin/sh, but /bin/tcsh is too clever
> for it's own good and blows up.
> 
> If you need a command that will expand character escapes in the target
> of a substitution command try:
> 
> % echo "bibble babble" | perl -p -e 's/ /\n/g;'
> bibble
> babble
> 
> 	Cheers
> 
> 	Matthew
> 

--
Rob Ellis <rob@web.ca>
System Administrator, Web Networks

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020618131606.GA18107>