Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Banging My Head Against Grep Wall

I'm trying to filter lines out of a log within a shell script, with line like this...

cat log | grep -v "filter word" | grep -v "filter 2" > newLog

...but I cannot find the grep or egrep command for something slightly more complex than a simple match.

I want to exclude (delete) all lines ending with "/" EXCEPT if they begin with "deleting".

So a file which contains these 4 lines...

this gets through
deleting - this gets through/
deleting - this gets through
this does NOT get through/

...will result in this...

this gets through
deleting - this gets through/
deleting - this gets through

Thanks very much for any pointers. Maybe I shouldn't be trying it with just grep?

Posted on Nov 11, 2009 5:13 AM

Reply
Question marked as Best reply

Posted on Nov 11, 2009 5:52 AM

This works for me at least for the small sample that you provide:
grep '^deleting.*/$|[^>$' log > newLog

What it lets through is:
1. Lines that begin with deleting AND end in /
2. Lines that do not end in a /
I hope that this does what you need.

Message was edited by: hungryjoe

Message was edited by: hungryjoe

Message was edited by: hungryjoe
2 replies
Question marked as Best reply

Nov 11, 2009 5:52 AM in response to David_x

This works for me at least for the small sample that you provide:
grep '^deleting.*/$|[^>$' log > newLog

What it lets through is:
1. Lines that begin with deleting AND end in /
2. Lines that do not end in a /
I hope that this does what you need.

Message was edited by: hungryjoe

Message was edited by: hungryjoe

Message was edited by: hungryjoe

Banging My Head Against Grep Wall

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.