Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Dec 1998 08:32:16 -0800
From:      Greg Shenaut <greg@bogslab.ucdavis.edu>
To:        questions@FreeBSD.ORG
Cc:        Greg Black <gjb@acm.org>
Subject:   Re: Sed sillyness (stupid question?) 
Message-ID:  <199812301632.IAA21206@deal1.bogs.org>
In-Reply-To: Your message of "Wed, 30 Dec 1998 20:56:15 %2B1000." <19981230105616.7077.qmail@alice.gba.oz.au> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <19981230105616.7077.qmail@alice.gba.oz.au>, Greg Black cleopede:
>> Why doesnt this work:
>> 
>> sed 's,test,te\nst,' 
>> 
>> That is when test is found how come sed doesnt actually print the newline
>> character?
>
>What you need is:
>
>sed 's,test,te\
>st,'
>
>In other words, you need a real backslash character followed by
>a real newline character -- not some code for it like "\n".

To avoid splitting the sed command across two lines, sometimes
something like this helps (at least under (pd)ksh):

  NL="\\^J"			(to get ^J, type CTL-V CTL-J)
  ... sed -e "s/xyz/xx${NL}yy/" ...

or, you can set NL="^J" and use "s/xyz/xx\\${NL}yy/", same difference.
Note that you have to use "" for the sed expression with this method, not ''.

-Greg Shenaut

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?199812301632.IAA21206>