Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.wizards Subject: Re: serious awk bug Keywords: awk Message-ID: <1990Mar14.171258.487@iwarp.intel.com> Date: 14 Mar 90 17:12:58 GMT References: <702@chem.ucsd.EDU> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Followup-To: poster Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 52 In-Reply-To: tps@chem.ucsd.edu (Tom Stockfisch) In article <702@chem.ucsd.EDU>, tps@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/;' <