Date: Sun, 30 Nov 2008 09:15:15 -0800 From: Gary Kline <kline@thought.org> To: Giorgos Keramidas <keramida@ceid.upatras.gr> Cc: FreeBSD Mailing List <freebsd-questions@freebsd.org> Subject: Re: for awk experts only. Message-ID: <20081130171515.GA25123@thought.org> In-Reply-To: <8763m535qm.fsf@kobe.laptop> References: <20081130045944.GA94896@thought.org> <8763m535qm.fsf@kobe.laptop>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Nov 30, 2008 at 11:47:29AM +0200, Giorgos Keramidas wrote: > On Sat, 29 Nov 2008 20:59:51 -0800, Gary Kline <kline@thought.org> wrote: > > wordnet/wn prints the string "noun" out whereas I'd rather it simply > > printed "n." Is there a way of making this substitution using awk? > > (I've never used awk except as a cmdline filter.) > > > > The following fails: > > > > wn foot -over |grep Overview |awk > > {if(!strcmp($3,"noun"))$3="n."; '{printf("%s %s\n", $4, $3);}}' > > > > If there are any shortcuts, please clue me in! > > Don't do this with a long stream of if/else/.../else blocks. AWK is a > pattern based rule-language. You can apply different blocks of code to > lines that match patterns like this: > > $3 ~ /adjective/ { print $1,"adj." } > $3 ~ /noun/ { print $1,"n." } > $3 ~ /verb/ { print $1,"v." } Thank you! Would I enclose the three lines with "BEGIN", and end with an "exit;" at the end? > -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081130171515.GA25123>