bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: possible bug in gawk 3.1.3


From: Stepan Kasal
Subject: Re: possible bug in gawk 3.1.3
Date: Tue, 20 Apr 2004 13:40:17 +0200
User-agent: Mutt/1.4.1i

Hello,
        thnak you for taking care to report your problems with gawk.

On Mon, Apr 19, 2004 at 01:07:34AM -0600, Robert Dalton wrote:
> %awk 'FS = "[\133\135]" {print $2}'
> %awk 'FS = "[\074\076]" {print $2}'

The quick answer: your code is not correct, use
        awk 'BEGIN{FS = "[][]"} {print $2}'
or perhaps
        awk '{split($0,a,/[[\]]/);print a[2]}'
instead.

The explanation:

I suppose you run this on one line input only, like this:

echo "<bobooAyahho.corp>" | awk 'FS = "[\074\076]" {print $2}'

You should know that when you write "[\074\076]", you get exactly
the same four-character string constant as if you wrote "[<>]" directly.
So in the when you write the string "[[]]" which compiles
to regex /\[]/, ie. it's the same as if you wrote "\\[]".

Another problem: when you execute
        echo '<A>' | awk 'FS = "[<>]" {print $2}' 

it doesn't extract the "email" ("A" in this example), as the field
splitting happens before the pattern-action pairs are evaluated.
When your pattern expression changes the FS as a side effect,
it's too late.

The above code worked with some older versions of gawk, but _that_
was a bug.  (An incorrect optimization.)

Just to enter some black magic, the following would work:
        echo '<A>' | awk 'FS = "[<>]" {$0=$0; print $2}'

Suggested read:
http://www.gnu.org/software/gawk/manual/html_node/Computed-Regexps.html
http://www.gnu.org/software/gawk/manual/html_node/Field-Separators.html

HTH,
        Stepan Kasal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]