Share your knowledge at the LQ Wiki.
Go Back > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.


  Search this Thread
Old 10-18-2007, 06:44 AM   #1
Registered: Feb 2004
Distribution: Solaris 10/11 , RHEL 6 ,AIX 7.1
Posts: 193

Rep: Reputation: 32
how to grep multiple filters with grep

# cat /etc/hello_word |grep abc

This command will filer word abc from the file hello_world

How can I filter multiple world with command e.g.
I want to filter two different words abc and xyz from this file.
Old 10-18-2007, 08:12 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735
Bash "alternation operator"---a fancy way of saying "or"

cat filename | egrep '(abc|xyz)'

egrep because we're using an extended regular expression

For the purists, the most efficient command is:

egrep '(abc|xyz)' filename
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
grep multiple strings GEEXTER Linux - General 7 12-06-2013 10:56 PM
grep for multiple patterns???? lucastic Linux - Software 4 08-06-2010 07:07 PM
need to search (grep) multiple directories red_nexus Linux - Newbie 5 07-04-2006 11:44 PM
Using grep to change multiple files zwyrbla Linux - General 5 01-11-2005 03:14 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM

All times are GMT -5. The time now is 09:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration