2 Aug 2012 13:20
buggy awk regex handling?
kaltheat <kaltheat <at> googlemail.com>
2012-08-02 11:20:52 GMT
2012-08-02 11:20:52 GMT
Hi,
I tried to replace three letters with three letters by awk using the sub-routine.
I assumed that my regular expression does mean the following:
match if three letters of any letter of alphabet occurs anywhere in input
$ echo AbC | awk '{sub(/[[:alpha:]]{3}/,"cBa"); print;}'
AbC
As you can see the result was unexpected.
When I try doing it for at least one letter, it works:
$ echo AbC | awk '{sub(/[[:alpha:]]+/,"cBa"); print;}'
cBa
Same problem without macro:
$ echo AbC | awk '{sub(/[A-Za-z]{3}/,"cBa"); print;}'
AbC
$ echo AbC | awk '{sub(/[A-Za-z]+/,"cBa"); print;}'
cBa
I thought that it might have something to do with the curly braces. But escaping
them doesn't do the trick.
What am I doing wrong?
Or is awk buggy?
(Continue reading)
RSS Feed