From owner-freebsd-questions Tue Jun 18 6:16:12 2002 Delivered-To: freebsd-questions@freebsd.org Received: from spin.web.net (spin.web.net [192.139.37.16]) by hub.freebsd.org (Postfix) with ESMTP id 4172D37B40B for ; Tue, 18 Jun 2002 06:16:04 -0700 (PDT) Received: by spin.web.net (Postfix, from userid 1000) id B135712E995; Tue, 18 Jun 2002 09:16:06 -0400 (EDT) Date: Tue, 18 Jun 2002 09:16:06 -0400 From: Rob Ellis To: freebsd-questions@FreeBSD.ORG Subject: Re: OT: using sed to insert \n at command line Message-ID: <20020618131606.GA18107@web.ca> Mail-Followup-To: Rob Ellis , freebsd-questions@FreeBSD.ORG References: <5.1.1.6.0.20020618161418.020a7780@wheresmymailserver.com> <20020618065319.GA68146@happy-idiot-talk.infracaninophi> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020618065319.GA68146@happy-idiot-talk.infracaninophi> User-Agent: Mutt/1.3.28i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 System Administrator, Web Networks To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message