2

I am trying to match the followings with egrep '201411[08|09|10|11]-[117|111]-'

20141108-111-xyz-abc
20141110-117-342-lala

But for some reasons, the 2nd character class pattern ([117|111]) doesn't work. It matches all regardless.

Any idea what goes wrong in my 2nd character class pattern?

  • Nothing to do with the problem at hand, but according to man grep,egrep has been deprecated and grep -E should be used. – Anthon Nov 12 '14 at 5:10
  • thanks for pointing out. I just tried grep -E just in case. Same issue. – Hei Nov 12 '14 at 5:13
3

You mix up character classes with subpatterns. You need the latter here:

grep -E '201411(08|09|10|11)-(117|111)-' file

"Character class" means: Every single char from the class (like [[:alpha:]]) or selection ([01][8901]) may appear.

"Subpattern" (with |) means: "One of the patterns separated by | may appear."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.