Date: Fri, 14 Jan 2011 17:53:04 +1030 From: Wayne Sierke <ws@au.dyndns.ws> To: Polytropon <freebsd@edvax.de> Cc: freebsd-questions@freebsd.org, Robert Bonomi <bonomi@mail.r-bonomi.com> Subject: Re: awk question: replacing "%d%s" by "%d %s" Message-ID: <1294989784.2037.79.camel@predator-ii.buffyverse> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2011-01-14 at 07:17 +0100, Polytropon wrote:
> On Thu, 13 Jan 2011 18:22:18 -0600 (CST), Robert Bonomi <bonomi@mail.r-bonomi.com> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1294989784.2037.79.camel>
