Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

This question already has an answer here:

How would I display the lines that do not contain certain letters? This is what I have already tried unsuccessfully to show the lines that do not consist of an a or b:

egrep *[^ab]* filename
share|improve this question

marked as duplicate by Radu Rădeanu, Warren Hill, guntbert, Eric Carvalho, Thomas Ward Sep 29 '13 at 18:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

You have this answer in one of the comments on a previous answer to another question of yours. You should read them! Also see man grep; it can learn you a lot. – Radu Rădeanu Sep 29 '13 at 6:38

Just use invert matching:

grep -v "[ab]" filename

Source: man page for grep

share|improve this answer
Don't forget to quote the pattern to grep. If the current directory happens to have the two files named a and b, the command will turn into grep -v a b filename, which does something different than intended. So: grep -v '[ab]' filename – geirha Sep 29 '13 at 10:38
@geirha: Oh yes, thanks! – i08in Sep 29 '13 at 10:39

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