2 Replies Latest reply: Nov 11, 2009 5:52 AM by hungryjoe
David_x Level 4 Level 4 (3,010 points)
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?
  • 1. Re: Banging My Head Against Grep Wall
    hungryjoe Level 2 Level 2 (250 points)
    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. Re: Banging My Head Against Grep Wall
    David_x Level 4 Level 4 (3,010 points)
    Perfect! Thanks. I was getting so blinkered on using "grep -v" to EXCLUDE lines! Because of that I could not find a combination using the "|". DOH!

    Wish I'd posted here 3 hours ago