Register
It is currently Fri Oct 31, 2014 10:27 am

grep multiple words any order on single line


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Jul 26, 2010 10:39 pm   

Joined: Mon Jul 26, 2010 10:31 pm
Posts: 2
I've been searching for a while and can't figure out how to search in multiple files for single lines that contain two or more words in any order, e.g. betty & veronica or veronica and betty. Piping ( grep betty.*veronica * | grep veronica.*betty *)doesn't work as the first grep only supplies the filenames and not the specific lines to the second grep (at least that's what appears to be happening)

Can anyone tell me how to do this?
thanks


Top
 Profile  
 PostPosted: Tue Jul 27, 2010 2:46 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Code:
~]# cat > temp/blah
abc
cba
bca
acb
cab
bac
def
fed
~]# egrep '(a.*c)|(c.*a)' temp/blah
abc
cba
bca
acb
cab
bac


Not exactly fully tested but off the top of my head that should be ok


Top
 Profile  
 PostPosted: Tue Jul 27, 2010 1:29 pm   

Joined: Mon Jul 26, 2010 10:31 pm
Posts: 2
Thank you Darth Wavy - it worked!


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP