From owner-freebsd-questions Mon Jun 17 23:53:31 2002 Delivered-To: freebsd-questions@freebsd.org Received: from smtp.infracaninophile.co.uk (happy-idiot-talk.infracaninophile.co.uk [81.2.69.218]) by hub.freebsd.org (Postfix) with ESMTP id 71A5237B407 for ; Mon, 17 Jun 2002 23:53:27 -0700 (PDT) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost.infracaninophile.co.uk [IPv6:::1]) by smtp.infracaninophile.co.uk (8.12.3/8.12.3) with ESMTP id g5I6rPnt068285; Tue, 18 Jun 2002 07:53:25 +0100 (BST) (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost) by happy-idiot-talk.infracaninophile.co.uk (8.12.3/8.12.3/Submit) id g5I6rJeJ068284; Tue, 18 Jun 2002 07:53:19 +0100 (BST) Date: Tue, 18 Jun 2002 07:53:19 +0100 From: Matthew Seaman To: Jacob Rhoden Cc: freebsd-questions@FreeBSD.ORG Subject: Re: OT: using sed to insert \n at command line Message-ID: <20020618065319.GA68146@happy-idiot-talk.infracaninophi> References: <5.1.1.6.0.20020618161418.020a7780@wheresmymailserver.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5.1.1.6.0.20020618161418.020a7780@wheresmymailserver.com> User-Agent: Mutt/1.3.99i 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 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