Date: Tue, 18 Jun 2002 07:53:19 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: Jacob Rhoden <f3z@iprimus.com.au> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: OT: using sed to insert \n at command line Message-ID: <20020618065319.GA68146@happy-idiot-talk.infracaninophi> In-Reply-To: <5.1.1.6.0.20020618161418.020a7780@wheresmymailserver.com> References: <5.1.1.6.0.20020618161418.020a7780@wheresmymailserver.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 -- Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way Tel: +44 1628 476614 Marlow Fax: +44 0870 0522645 Bucks., SL7 1TH UK 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?20020618065319.GA68146>