Date: Sat, 31 Jan 2004 17:31:05 -0800 From: Chris Pressey <cpressey@catseye.mine.nu> To: Daniela <dgw@liwest.at> Cc: questions@freebsd.org Subject: Re: OT: sed problem Message-ID: <20040131173105.434eed14.cpressey@catseye.mine.nu> In-Reply-To: <200402010138.44102.dgw@liwest.at> References: <200402010138.44102.dgw@liwest.at>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 1 Feb 2004 01:38:44 +0000 Daniela <dgw@liwest.at> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040131173105.434eed14.cpressey>