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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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
share|improve this answer
    
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 '12 at 22:49

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.