From owner-freebsd-questions@FreeBSD.ORG Sun Nov 30 09:47:42 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 8E8B3106564A for ; Sun, 30 Nov 2008 09:47:42 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 06E5B8FC0C for ; Sun, 30 Nov 2008 09:47:41 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) 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 mAU9lWx7013967 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 30 Nov 2008 11:47:38 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id mAU9lW7k059377; Sun, 30 Nov 2008 11:47:32 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id mAU9lTpm059376; Sun, 30 Nov 2008 11:47:29 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Gary Kline References: <20081130045944.GA94896@thought.org> Date: Sun, 30 Nov 2008 11:47:29 +0200 In-Reply-To: <20081130045944.GA94896@thought.org> (Gary Kline's message of "Sat, 29 Nov 2008 20:59:51 -0800") Message-ID: <8763m535qm.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: mAU9lWx7013967 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.818, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.58, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr 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 09:47:42 -0000 On Sat, 29 Nov 2008 20:59:51 -0800, Gary Kline 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." }