egrep -i '12-12.*\swarning' log.file | cless

The above will produce two lines with the date 12-12, followed by random characters, a white space, then Warning and more text.

2011-12-12 textetc Warning 1234
2011-12-12 textetc Warning 5678

I wish it only to return lines that DO NOT contain 1234 at the end. I'm using GNU grep 2.5.4.

Currently, this is my workaround.

egrep -i '12-12.*\swarning' log.file > tmp.txt
egrep -i -v '1234' tmp.txt

I've tried piping the first to the second (without creating a file), but it either returns way too much, and it's all wrong, or it returns nothing at all.

1 Answer 1


You have to use 2 greps.

grep -i '12-12.*[[:space:]]warning' log.file | grep -v '1234$'

Alternatively, you could use one awk

awk '/12-12.*[[:space:]]warning/ && ! /1234$/' log.file
  • Thanks! You solved my issue with the first line. My problem was that I thought I had to add the file I was grepping in the second statement.
    – r.misc
    Feb 17, 2012 at 22:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .