I have a piece of a sed script that is working correctly and I'm not sure why. This bothers me.
The replacement rule is supposed to change a function of the form:
into:
This is my rule:
If I execute:
I get:
I don't understand why the marked comma in the rule is matching the marked comma in the input, rather than the preceding comma. Does sed just try to find the longest possible match or something?
The replacement rule is supposed to change a function of the form:
Code:
log(foo,fmt,arg1,arg2)
Code:
log(foo,fmt,(cast)arg1,(cast)arg2)
Code:
s/\(foo.*,.*\),\(.*\),\(.*\)/\1,(cast)\2,(cast)\3/ ^
Code:
echo 'log(foo,"omg,wtf",arg1,arg2)' | sed 's/\(foo.*,.*\),\(.*\),\(.*\)/\1,(cast)\2,(cast)\3/' ^
Code:
log(foo,"omg,wtf",(cast)arg1,(cast)arg2)
Comment