Date: Sun, 30 Nov 2008 11:47:29 +0200 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Gary Kline <kline@thought.org> Cc: FreeBSD Mailing List <freebsd-questions@freebsd.org> Subject: Re: for awk experts only. Message-ID: <8763m535qm.fsf@kobe.laptop> In-Reply-To: <20081130045944.GA94896@thought.org> (Gary Kline's message of "Sat, 29 Nov 2008 20:59:51 -0800") References: <20081130045944.GA94896@thought.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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." }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8763m535qm.fsf>