From owner-freebsd-questions@FreeBSD.ORG Sat Jan 31 17:26:47 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 C45A816A4CE for ; Sat, 31 Jan 2004 17:26:47 -0800 (PST) Received: from priv-edtnes57.telusplanet.net (defout.telus.net [199.185.220.240]) by mx1.FreeBSD.org (Postfix) with ESMTP id 97C8843D3F for ; Sat, 31 Jan 2004 17:26:46 -0800 (PST) (envelope-from cpressey@catseye.mine.nu) Received: from catseye.biscuit.boo ([207.81.17.215]) by priv-edtnes57.telusplanet.netSMTP <20040201012646.WASY25051.priv-edtnes57.telusplanet.net@catseye.biscuit.boo>; Sat, 31 Jan 2004 18:26:46 -0700 Date: Sat, 31 Jan 2004 17:31:05 -0800 From: Chris Pressey To: Daniela Message-Id: <20040131173105.434eed14.cpressey@catseye.mine.nu> In-Reply-To: <200402010138.44102.dgw@liwest.at> References: <200402010138.44102.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 01:26:47 -0000 On Sun, 1 Feb 2004 01:38:44 +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. It sounds like awk might be better suited to what you want to do than sed. You should be able to do something like this with sh and awk: cat test.txt | awk -F'|' '{ print $1,$2,$3 }' | \ while read VAR1 VAR2 VAR3; do # do something with $VAR1, $VAR2, and $VAR3 done So if test.txt contains a|b|c d|e|f On the first iteration of the while loop, VAR1=a, VAR2=b, and VAR3=c, and on the second iteration... well, you get the idea :) -Chris