Server Fault is a question and answer site for system and network administrators. 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

I would like to search for lines that contain "uploaded" but do not contain "09"

Is there a way to do this with grep?

(CentOS 5.6 if it matters).

share|improve this question
up vote 7 down vote accepted

I usually chain greps to do this.

grep uploaded $file | grep -v 09
share|improve this answer

You can use the -v option to grep to invert the match so

grep uploaded file | grep -v 09

will do what you want. This finds the lines that contain uploaded which are passed piped into a grep command to ignore lines with 09 in them.

share|improve this answer

This isn't using grep - but anytime I have a need that requires more than a basic grep, I turn to my favorite, sed. Certainly any time I have to chain grep commands together...

Use this command to do it:

sed -n '/09/d; /uploaded/p' file

Just one single command (not two).

share|improve this answer

Try simply:

( grep -v 09 | grep uploaded ) < file


$ cat file
1 uploaded 09
2 09
3 uploaded
4 text
$ ( grep -v 09 | grep uploaded ) < file
3 uploaded
share|improve this answer

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.