for awk experts only.
Giorgos Keramidas
keramida at ceid.upatras.gr
Sun Nov 30 01:47:42 PST 2008
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." }
More information about the freebsd-questions
mailing list