Can someone explain why this code does not work as expected? I would expect it to only match the first character, and it has alphabetic characters, but the wildcard classes (.) And characters behave strangely:
I use -o just to show exactly how things match, it doesn't change what matches at all.
$ echo foo | grep -o '^.'
f
o
o
More unexpected behavior:
$ echo foobarbazquux | grep -o '^[foarqux]'
f
o
o
$ echo foobarbazquux | grep -o '^.[^u]'
fo
ob
ar
ba
zq
Typically, start-string (^) does not behave as expected in these cases. Is there a way to make him behave more normally?
source
share