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