Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer

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:

mmmmmz09123
00
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
add comment

Your Answer

 
discard

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.