for awk experts only.

Gary Kline kline at thought.org
Sun Nov 30 09:15:24 PST 2008


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 at 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 at thought.org  http://www.thought.org  Public Service Unix
        http://jottings.thought.org   http://transfinite.thought.org




More information about the freebsd-questions mailing list