Reputation: 422
The following command with sed and simple regexp:
echo 'Atest Atest Atest' | sed -E 's/A|$/B/g'
produces output:
Btest Btest B
Could someone explain, please, why does sed eat last word? I expected the output to be something like this:
Btest Btest BtestB
I use sed version bundled with Mac OS ("BSD-flavour").
Update This behaviour looks like a bug, comparing to GNU sed, so I've chosen to stick to the latter one.
Upvotes: 2
Views: 126
Reputation: 785196
Interesting, this appears to be some bug (weird behavior) in BSD sed available on OSX. I can reproduce this behavior. Looks this behavior happens only with g
flag.
To fix this I would suggest use this equivalent sed
command:
echo 'Atest Atest Atest' | sed 's/A/B/g;s/$/B/'
Btest Btest BtestB
Upvotes: 3