From owner-freebsd-questions@FreeBSD.ORG Fri Jan 14 07:38:26 2011 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 4A4DB1065672 for ; Fri, 14 Jan 2011 07:38:26 +0000 (UTC) (envelope-from ws@au.dyndns.ws) Received: from ipmail04.adl6.internode.on.net (ipmail04.adl6.internode.on.net [150.101.137.141]) by mx1.freebsd.org (Postfix) with ESMTP id BDBB28FC12 for ; Fri, 14 Jan 2011 07:38:25 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApEBACuIL02WZWdv/2dsb2JhbAAM4zuFTwQ Received: from ppp103-111.static.internode.on.net (HELO [192.168.1.144]) ([150.101.103.111]) by ipmail04.adl6.internode.on.net with ESMTP; 14 Jan 2011 17:53:07 +1030 From: Wayne Sierke To: Polytropon In-Reply-To: <20110114071712.c7a7fe7e.freebsd@edvax.de> References: <20110113062819.4ecb89d9.freebsd@edvax.de> <201101140022.p0E0MIW8029158@mail.r-bonomi.com> <20110114071712.c7a7fe7e.freebsd@edvax.de> Content-Type: text/plain; charset="ASCII" Date: Fri, 14 Jan 2011 17:53:04 +1030 Message-ID: <1294989784.2037.79.camel@predator-ii.buffyverse> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org, Robert Bonomi Subject: Re: awk question: replacing "%d%s" by "%d %s" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: ws@au.dyndns.ws List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Jan 2011 07:38:26 -0000 On Fri, 2011-01-14 at 07:17 +0100, Polytropon wrote: > On Thu, 13 Jan 2011 18:22:18 -0600 (CST), Robert Bonomi wrote: > > True. But > > sub(nr,"[a-z]"," &"); > > > > does the trick. (tested on Freebsd 7.2) > > > > Explamation: "&" is a 'replacement side' magic incantation to the regex > > library that means 'that which was matched by the pattern regex'. > > Doesn't work on my 7-STABLE system (20080811), awk stops: > > awk: syntax error at source line 78 source file konvertieren.awk > context is > sub(nr, "[a-z]", " >>> &" <<< ); > awk: illegal statement at source line 79 source file konvertieren.awk > > But I'll keep your suggestion in the program source and test > it on 8 as soon as my "new" home system is ready to use. At > least, the & variant looks much better. I suspect it is a transcription error by Robert in his email. >From man awk: sub(r, t, s) substitutes t for the first occurrence of the regular expression r in the string s. If s is not given, $0 is used. So the correct syntax is: sub("[a-z]", " &", nr) Wayne