From owner-freebsd-questions@FreeBSD.ORG Sun Nov 30 17:15:24 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 20D051065730 for ; Sun, 30 Nov 2008 17:15:24 +0000 (UTC) (envelope-from kline@thought.org) Received: from aristotle.thought.org (ns1.thought.org [209.180.213.210]) by mx1.freebsd.org (Postfix) with ESMTP id D3DFE8FC13 for ; Sun, 30 Nov 2008 17:15:23 +0000 (UTC) (envelope-from kline@thought.org) Received: from thought.org (tao.thought.org [10.47.0.250]) (authenticated bits=0) by aristotle.thought.org (8.14.2/8.14.2) with ESMTP id mAUHFmsR044291; Sun, 30 Nov 2008 09:15:48 -0800 (PST) (envelope-from kline@thought.org) Received: by thought.org (nbSMTP-1.00) for uid 1002 kline@thought.org; Sun, 30 Nov 2008 09:15:16 -0800 (PST) Date: Sun, 30 Nov 2008 09:15:15 -0800 From: Gary Kline To: Giorgos Keramidas Message-ID: <20081130171515.GA25123@thought.org> References: <20081130045944.GA94896@thought.org> <8763m535qm.fsf@kobe.laptop> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8763m535qm.fsf@kobe.laptop> User-Agent: Mutt/1.4.2.3i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: With 22 years of service to the Unix community. X-Spam-Status: No, score=-4.4 required=3.6 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on aristotle.thought.org 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 17:15:24 -0000 On Sun, Nov 30, 2008 at 11:47:29AM +0200, Giorgos Keramidas wrote: > 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." } Thank you! Would I enclose the three lines with "BEGIN", and end with an "exit;" at the end? > -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org