retitle 100808 gsub doesn't respect ^ when the pattern matches the empty string
thanks

This bug has nothing to do with $0.  BTW, the awk standard
http://www.opengroup.org/onlinepubs/009695399/utilities/awk.html 
does require updating $0: see paragraph 3 of the Description.
And mawk does do that.

echo -e "barfoo\nbo bo fo\n1 2 3" | mawk '{$1="foo"; print $0}'
foo
foo bo fo
foo 2 3

 The problem is with gsub, so the merge with 172774 is correct.
Nobody bothered to post anything about that on this bug page, though!

This mawk bug boils down to mawk not respecting ^ when the pattern
matches the empty string.  (I haven't dug into mawk's regex code, or
tried other permutations, so while this new title is correct, it might
not be where the bug is really coming from.)


 mawk 'BEGIN{s=" foo bar";gsub(/^ */, "_", s);print s;}'</dev/null
_f_o_o_b_a_r_
 gawk 'BEGIN{s=" foo bar";gsub(/^ */, "_", s);print s;}'</dev/null
_foo bar

There is a workaround: don't match the empty string when you don't
need to.
 mawk 'BEGIN{s=" foo bar";gsub(/^ +/, "_", s);print s;}'</dev/null
_foo bar

 This doesn't help if you wanted to use gsub to prepend something by
replacing the empty string at the start, though.

 mawk 'BEGIN{s=" foo bar";gsub(/^/, "_", s);print s;}'</dev/null
_ _f_o_o_ _b_a_r_
 gawk 'BEGIN{s=" foo bar";gsub(/^/, "_", s);print s;}'</dev/null
_ foo bar

-- 
#define X(x,y) x##y
Peter Cordes ;  e-mail: X([EMAIL PROTECTED] , des.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BC



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to