From owner-freebsd-questions@FreeBSD.ORG Sun Feb 1 10:06:08 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F119516A4CE for ; Sun, 1 Feb 2004 10:06:08 -0800 (PST) Received: from priv-edtnes03-hme0.telusplanet.net (outbound01.telus.net [199.185.220.220]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6E01D43D45 for ; Sun, 1 Feb 2004 10:06:07 -0800 (PST) (envelope-from cpressey@catseye.mine.nu) Received: from catseye.biscuit.boo ([207.81.17.215]) by priv-edtnes03-hme0.telusplanet.netSMTP <20040201180607.DMSY26154.priv-edtnes03-hme0.telusplanet.net@catseye.biscuit.boo>; Sun, 1 Feb 2004 11:06:07 -0700 Date: Sun, 1 Feb 2004 10:10:27 -0800 From: Chris Pressey To: Daniela Message-Id: <20040201101027.2b90499d.cpressey@catseye.mine.nu> In-Reply-To: <200402011533.58877.dgw@liwest.at> References: <200402010138.44102.dgw@liwest.at> <20040201013401.GA35376@users.munk.nu> <200402011533.58877.dgw@liwest.at> Organization: Cat's Eye Technologies X-Mailer: Sylpheed version 0.9.8a (GTK+ 1.2.10; i386-portbld-freebsd4.9) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit cc: questions@freebsd.org Subject: Re: OT: sed problem X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Feb 2004 18:06:09 -0000 On Sun, 1 Feb 2004 15:33:58 +0000 Daniela wrote: > On Sunday 01 February 2004 01:34, Jez Hancock wrote: > > On Sun, Feb 01, 2004 at 01:38:44AM +0000, Daniela wrote: > > > I was wondering how I can do the following with sed (or another > > > program): 1. Output only the text from the start of the line to > > > the first pipe character 2. Output only the text between the last > > > and the previous pipe character Or, split the line at the pipe > > > characters and assign the parts to different shell variables. > > > > #!/bin/sh > > test="one|two|three" > > set `echo "$test" | sed -e 's/\|/ /g'` > > > > # $1="one", $2="two", $3="three": > > echo $@ > > This doesn't work when the parts between the pipe characters contain > spaces themselves. Nor does the awk approach I posted, incidentally - the problem being that sh likes to split up its input into variables, by spaces. You can work around it by translating the spaces into some unused character first, then translating pipes to spaces, then finally translating the unused characters back into spaces in each of the variables. There may be a simpler way, but if so, I don't know what it is. Or you could avoid sh variables and do whatever processing you have to do entirely in awk (or perl.) -Chris