What does this egrep command do?

egrep '[^A-M][0-9]+' /etc/passwd

So far I think it searches for any file in /etc/passwd that starts with A-M and includes the number(s) 0-9. Is that right?


^ at the beginning of an expression means "beginning of line". However, ^ inside a bracket expression matches everything not in that expression. So, for example, while [abcd] matches the letters a, b, c, or d, the expression [^abcd] matches everything other than those letters.

So the expression you've got matches "anything not A-M, followed by 1 or more digits".

The following lines would all match that expression:

this is a very long line that includes the number 1.

Because they all contain a digit preceded by something that is not in the range A-M.

  • Thanks for helping and correcting me. egrep and it's expressions are very much clear to me now, awesome!
    – k3n
    Mar 14 '12 at 2:47
  • I'm glad this helped out! If you like the answer you may want to mark it as "accepted" by clicking on the checkbox on the left. Thanks!
    – larsks
    Mar 14 '12 at 2:52

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.