serious awk bug
Magnus Gislason
magnus at rhi.hi.is
Thu Mar 15 02:36:43 AEST 1990
tps at chem.ucsd.edu (Tom Stockfisch) writes:
>The following awk script doesn't behave properly:
>#! /bin/sh
>awk '/^a*[^b]/ { print "1:", $0 }
>/^a*b/ { print "2:", $0 }
>'
[stuff deleted]
>Basically, the line "ab" should match only rule 2, but it matches both
>rules. The following script:
In Regular Expressions `a*' meens 0 or more occurrencies of `a' and
`[^b]' meens any character except `b'. In this case `a*[^b]' matches
0 `a's followed by a character that is not `b' (in this case `a').
I tried this with grep, egrep, sed and vi and they all behaved like awk
so I suppose it's the correct way.
More information about the Comp.unix.wizards
mailing list