- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- AWK: matching 2 or more Patterns
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
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
тАО08-13-2009 12:53 PM
тАО08-13-2009 12:53 PM
With 1 stream:
someprog | awk F: '/pattern1/ {print $3}'
What if I have 2 or more patterns? Is it possible so I do not resort to multiple awk lines?
TIA... sorry I am getting rusty with the Shell and its utils.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2009 12:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2009 12:09 AM
тАО08-14-2009 12:09 AM
Re: AWK: matching 2 or more Patterns
Besides JRF's ERE, you can use multiple patterns with ||:
'/line-1/ || /line-3/ { print }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2009 10:13 PM
тАО08-17-2009 10:13 PM
Re: AWK: matching 2 or more Patterns
# echo $output | egrep 'pattern1|pattern2|pattern3'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 01:10 AM
тАО08-18-2009 01:10 AM
Re: AWK: matching 2 or more Patterns
Why? The whole purpose of a pattern in awk is to not use an extra grep process.
And using the "|" in egrep is the same as "|" in awk.
But if you want to use grep, don't use the egrep hammer for this simple case, use multiple "-e patterns".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 02:59 AM
тАО08-18-2009 02:59 AM
Re: AWK: matching 2 or more Patterns
>Why? The whole purpose of a pattern in awk is to not use an extra grep process.
Do you mean with extra grep usage here will affect runtime ? awk will work faster ?
>And using the "|" in egrep is the same as "|" in awk.
I know , just wanted to show alternative way. .
>But if you want to use grep, don't use the egrep hammer for this simple case, use multiple "-e patterns".
Yes, I know grep -E 'pattern1|pattern2' == egrep 'pattern1|pattern2' .
And you prefer grep in case of egrep not available in the system or what ? Can you explain Dennis ?
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-18-2009 08:03 AM
тАО08-18-2009 08:03 AM
Re: AWK: matching 2 or more Patterns
Possibly. If invoking awk anyway, why add a grep.
>And you prefer grep in case of egrep not available in the system or what?
Instead of egrep's ERE, use grep's RE:
grep -e pattern1 -e pattern2