From owner-freebsd-questions@FreeBSD.ORG Sun Nov 30 18:04:14 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3ED85106564A for ; Sun, 30 Nov 2008 18:04:14 +0000 (UTC) (envelope-from keramida@freebsd.org) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id AAE708FC17 for ; Sun, 30 Nov 2008 18:04:13 +0000 (UTC) (envelope-from keramida@freebsd.org) Received: from kobe.laptop (adsl144-35.kln.forthnet.gr [195.74.243.35]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-5) with ESMTP id mAUI45In009843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 30 Nov 2008 20:04:10 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id mAUI45Xl090570; Sun, 30 Nov 2008 20:04:05 +0200 (EET) (envelope-from keramida@freebsd.org) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id mAUI43An090569; Sun, 30 Nov 2008 20:04:03 +0200 (EET) (envelope-from keramida@freebsd.org) From: Giorgos Keramidas To: Gary Kline References: <20081130045944.GA94896@thought.org> <8763m535qm.fsf@kobe.laptop> <20081130171515.GA25123@thought.org> Date: Sun, 30 Nov 2008 20:04:03 +0200 In-Reply-To: <20081130171515.GA25123@thought.org> (Gary Kline's message of "Sun, 30 Nov 2008 09:15:15 -0800") Message-ID: <877i6lqeek.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: mAUI45In009843 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-4.247, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.15, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@freebsd.org X-Spam-Status: No Cc: FreeBSD Mailing List Subject: Re: for awk experts only. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Nov 2008 18:04:14 -0000 On Sun, 30 Nov 2008 09:15:15 -0800, Gary Kline 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.