• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get lines matching two patterns?  RSS feed

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Folks,
I know the command
grep -l 'pattern1' filename
print lines matching the pattern. I have a requirement to grep lines for multiple pattern,
for example , i want all the lines containing 'word1' or 'word2' or both. How can i use grep facility?
regs
Dez
 
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this:
man grep
if you page down a few times, you will find that the command:
grep -E 'abc def'
or
grep -F 'abc def'
will return all lines containing 'abc', 'def' or both.
 
Dez Max
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only to grep the lines whose third words matches the patterns specified. Can it be done in shell scripts?
I've manage to do it using awk.
regs
Dez
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!