for awk experts only.
Giorgos Keramidas
keramida at freebsd.org
Sun Nov 30 10:04:14 PST 2008
On Sun, 30 Nov 2008 09:15:15 -0800, Gary Kline <kline at thought.org> wrote:
>On Sun, Nov 30, 2008 at 11:47:29AM +0200, Giorgos Keramidas wrote:
>> 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?
Nope. None of the two.
'BEGIN' has a special meaning in awk patterns. It means "run this block
of code before you start reading any input records".
If you 'exit' somewhere in a code block, then awk will terminate the
script after the first line that matches the relevant pattern. This is
probably not quite what you want when awk filters through a long list of
words.
More information about the freebsd-questions
mailing list