grep XXX that not followed by YYY | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

grep XXX that not followed by YYY

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-10-2008
ynixon ynixon is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 18 March 2010, 4:36 AM EDT
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
grep XXX that not followed by YYY

I want to grep all lines containing blocking sess= that are not followed by 0x0

Code:
cat trace.log
blocking sess=0x0
blocking sess=0x0
rrrr......
blocking sess=121
blocking sess=0x0
blocking sess=0x0
blocking sess=0x0
some other lines
blocking sess=001
blocking sess=0x0
blocking sess=0x1

the grep output should be


Code:
blocking sess=121
blocking sess=001
blocking sess=0x1

any idea ?

Last edited by ynixon; 06-10-2008 at 09:26 AM..
Sponsored Links
    #2  
Old 06-10-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
 
Join Date: Apr 2002
Last Activity: 20 December 2009, 10:56 AM EST
Location: Italy
Posts: 370
Thanks: 0
Thanked 0 Times in 0 Posts
I seems that in your file you have only lines in the form "blocking sess=XxY"... So:


Code:
grep -v "blocking sess=0x0" trace.log

Sponsored Links
    #3  
Old 06-10-2008
ynixon ynixon is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 18 March 2010, 4:36 AM EDT
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by robotronic View Post
I seems that in your file you have only lines in the form "blocking sess=XxY"... So:


Code:
grep -v "blocking sess=0x0" trace.log

you are right, the example was wrong... I fixed the example see above
    #4  
Old 06-10-2008
navi navi is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 21 October 2008, 7:30 AM EDT
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
grep -v "0x0" trace.log
Sponsored Links
    #5  
Old 06-10-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
 
Join Date: Apr 2002
Last Activity: 20 December 2009, 10:56 AM EST
Location: Italy
Posts: 370
Thanks: 0
Thanked 0 Times in 0 Posts
Go with the "dirty and simple way":


Code:
grep -v "blocking sess=0x0" trace.log | grep "blocking sess"

Or try something different:


Code:
awk -F"=" '/blocking sess=/ && $2 != "0x0"' trace.log

Sponsored Links
    #6  
Old 06-10-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 16 September 2014, 11:09 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,673
Thanks: 182
Thanked 620 Times in 578 Posts
With Sed:


Code:
sed -n '/=0x0/!{/blocking sess=/p;}' trace.log


Last edited by radoulov; 06-10-2008 at 10:02 AM..
Sponsored Links
    #7  
Old 06-10-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 16 September 2014, 11:09 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,673
Thanks: 182
Thanked 620 Times in 578 Posts
Quote:
Originally Posted by navi View Post
grep -v "0x0" trace.log
This will not filter the lines with "rrrr......" and "some other lines"
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash - CLI - grep - Passing result to grep through pipe jcdole UNIX for Dummies Questions & Answers 1 04-29-2012 06:20 PM
Advanced grep'in... grep for data next to static element. SysAdm2 UNIX for Dummies Questions & Answers 2 01-05-2011 12:59 PM
grep for certain files using a file as input to grep and then move anita07 Shell Programming and Scripting 2 12-10-2009 03:59 AM
| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax MykC UNIX for Dummies Questions & Answers 4 10-15-2009 10:52 AM
| help | unix | grep - Can I use grep to return a string with exactly n matches? MykC UNIX for Dummies Questions & Answers 7 10-13-2009 01:57 PM



All times are GMT -4. The time now is 01:31 AM.