Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

^ 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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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