serious awk bug
Randal Schwartz
merlyn at iwarp.intel.com
Thu Mar 15 03:12:58 AEST 1990
In article <702 at chem.ucsd.EDU>, tps at chem (Tom Stockfisch) writes:
|
| The following awk script doesn't behave properly:
|
| #! /bin/sh
|
| awk '/^a*[^b]/ { print "1:", $0 }
| /^a*b/ { print "2:", $0 }
| '
|
| When given the following input
|
| b
| ab
|
| It produces the following output
|
| 2: b
| 1: ab
| 2: ab
|
| Basically, the line "ab" should match only rule 2, but it matches both
| rules.
[This doesn't belong in WIZARDS. Sorry.]
But, it *does* match rule 1! Look carefully. If you take zero 'a's,
and one 'not b', you can get line "ab"!
In Perl:
perl -ne 'print "1: $_" if /^a*[^b]/; print "2: $_" if /^a*b/;' <<EOF
b
ab
EOF
produces:
2: b
1: ab
2: ab
Just like awk. Amazing.
No problem.
Just another Perl and awk hacker,
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
More information about the Comp.unix.wizards
mailing list