Can someone explain why this code doesn’t work as expected?
I would expect it only to match the first character, and it does with literal characters, but the wildcard (.) and characters classes behave strangely:
I use -o just to demonstrate exactly how things are matching, it doesn’t change what matches at all.
$ echo foo | grep -o '^.'
f
o
o
Some more unexpected behavior:
$ echo foobarbazquux | grep -o '^[foarqux]'
f
o
o
$ echo foobarbazquux | grep -o '^.[^u]'
fo
ob
ar
ba
zq
Esentially the beginning-of-line matcher (^) is not behaving as expected in these cases. Is there any way to make it behave more normally?
Found it:
Bug
Changelog of fix
Apparently fixed in 2.5.2. Found it via launchpad.