[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: The awk bug
From: |
John Cowan |
Subject: |
Re: The awk bug |
Date: |
Fri, 27 Nov 2009 15:21:32 -0500 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Kaplenko Vitaliy scripsit:
> $ echo "./some_script" | awk 'gsub(".","a") {print $0}'
> aaaaaaaaaaaaa
>
> But must be:
>
> $ echo "./some_script" | awk 'gsub(".","a") {print $0}'
> a/some_script
Not so. The first argument of gsub is interpreted as a regular
expression, and "." in a regular expression means "any character".
Consequently, all characters in the input are replaced. You must use
"\." to match a literal dot.
> $ echo "some_script" | awk 'gsub("/","a") {print $0}'
> $
>
> But must be:
>
> $ echo "some_script" | awk 'gsub("/","a") {print $0}'
> $ some_script
Also not the case. You have placed the call to gsub into the pattern
part of the pattern-action statement. Consequently, it evaluates to 0
because there are no slashes in the input, and therefore the action is
never executed. A correct action statement would be
{gsub("/", a); print $0}
--
A rabbi whose congregation doesn't want John Cowan
to drive him out of town isn't a rabbi, http://www.ccil.org/~cowan
and a rabbi who lets them do it address@hidden
isn't a man. --Jewish saying
- The awk bug, Kaplenko Vitaliy, 2009/11/27
- Re: The awk bug,
John Cowan <=