I am to find lines in a file whose fifth character is a digit. That is, of the digit set {0123456789}. I made a file that had:
asdf1
asdf2
.. and so on until 0.
I made a few more cases with special characters, and other symbols just to make sure I wasn’t grabbing those lines either.
However, one thing intrigued me. When making the line:
SSSSS3
or
TTTTTS7
that is, where every S is a space, and T is a tab, that line is also retrieved when the fifth character is a space/tab and not a number.
Could anybody explain why this is happening?
The pattern I’m using is
'....[0-9](.)*'
If I’m not mistaken, a ‘.’ represents any character, right? How could more than 4 tabs or spaces count as less than 5 ‘.’?
You’re missing the start-of-line anchor:
Without it,
egrepperforms a regexp search rather than a regexp match, as if you had enteredthough with the difference that the
.*does not cause capturing for flags like-o.(Note that the
(.)*at the end is also useless..*is implicitly appended to the end of the RE unless you put in an end-of-line anchor,$.)