- Community Home
- >
- Servers and Operating Systems
- >
- Legacy
- >
- Operating System - Tru64 Unix
- >
- Re: how to grep on three items
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 03:50 AM
тАО03-05-2009 03:50 AM
i have a question, i need to grep on three items i a line of a logfile
like:
grep item1 and item2 and item3 /var/log/logfile
One option is to do:
grep item1 logfile | grep item2 | grep item3
but is there a nicer way ?
Kl@@s
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 05:47 AM
тАО03-05-2009 05:47 AM
Re: how to grep on three items
egrep "item1|item2|item3" logfile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 05:52 AM
тАО03-05-2009 05:52 AM
SolutionAlmost always. "man grep":
[...]
By default, the grep command treats a pattern as a basic regular expression
(BRE). With the -E option, the pattern is treated as an extended regular
expression (ERE). With the -F option, the pattern is considered a fixed
string. See the following discussion of regular expressions.
[...]
If you know the order of the items:
bash$ echo '11a22b33c44' | grep 'a.*b.*d'
bash$ echo '11a22b33c44' | grep 'a.*b.*c'
11a22b33c44
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 05:56 AM
тАО03-05-2009 05:56 AM
Re: how to grep on three items
> [...]
Really? For this problem? AND != OR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 06:16 AM
тАО03-05-2009 06:16 AM
Re: how to grep on three items
egrep -e item1 -e item2 logfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 06:27 AM
тАО03-05-2009 06:27 AM
Re: how to grep on three items
> question.
Nah. You messed up the _answer_.
> egrep -e item1 -e item2 logfile
Twice.
bash$ echo '11a22b33c44' | egrep -e a -e d
11a22b33c44
Testing is _such_ a bother.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 06:46 AM
тАО03-05-2009 06:46 AM
Re: how to grep on three items
Shame on me. Ok, last try, but let's avoid grep/egrep =)
awk '/item1/ && /item2/ { print $0 }' logfile
Tested with:
echo 11a22b33c44 | awk '/a/ && /d/ { print $0 }'
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 10:21 PM
тАО03-05-2009 10:21 PM
Re: how to grep on three items
>but is there a nicer way?
This is doing AND. If these items are in that order you can do:
grep "item1.*item2.*item3" logfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 10:23 PM
тАО03-05-2009 10:23 PM
Re: how to grep on three items
Oops, Steven already said that.
You could list all of the orders with -e. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2009 10:30 PM
тАО03-05-2009 10:30 PM
Re: how to grep on three items
In the meantime i've accepted the solution grep 'a.*b.*d' as for me the best option, but submitting points does not work for me at this moment due to firewall rules or something so this weekend i will do my job to thank you all the propper way!
Again thanks!