- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: egrep question
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-16-2011 05:22 PM
тАО03-16-2011 05:22 PM
I want to egrep for two different words in a single line using egrep.
lets say line is -
allan is a great man
egrep for allan and great in the same line else dont print that line.
Thanks,
Allan.
Solved! Go to Solution.
- Tags:
- egrep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 05:33 PM
тАО03-16-2011 05:33 PM
SolutionIf you want and AND relationship where both strings match:
# echo "allan is a great man"|grep allan|grep great
...but if you want an OR (alternation) where only one string need match:
# echo "allan is a great man"|grep -E "allan|great"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 07:56 PM
тАО03-16-2011 07:56 PM
Re: egrep question
Two "grep" processes? Ptui. Make one
process work harder:
alp$ echo 'allan is a great man' | egrep -e 'allan.*great|great.*allan'
allan is a great man
alp$ echo 'a great man is allan' | egrep -e 'allan.*great|great.*allan'
a great man is allan
As usual, everything's complicated, and the
fine print may matter. Case? Distinct
words, or strings anywhere?
alp$ echo 'greater gallantry' | egrep -e 'allan.*great|great.*allan'
greater gallantry
Of course, if the order is known, then the
regular expression could be simplified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 08:19 PM
тАО03-16-2011 08:19 PM
Re: egrep question
>> I want to egrep for two different words in a single line using egrep.
Hmmm, why would one feel one should use 'egrep' (fill in any other forcibly chosen tool) if one, apparently, does not know it well enough?
This _might_ be better solved with AWK
$ awk '/allan/ && /great/' your-file.txt
or perl
$ perl -ne 'print if /allan/ && /great/' your-file.txt
more perl, written more silly ...
$ perl -ne '/allan/ && /great/ && print' your-file.txt
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 09:03 PM
тАО03-16-2011 09:03 PM
Re: egrep question
Thanks guys
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2011 11:45 PM
тАО03-16-2011 11:45 PM
Re: egrep question
Why would you want to use the egrep hammer if you can use grep instead?
>egrep for allan and great in the same line
You can use this if you don't want a grep pipeline:
grep -e "allan.*great" -e "great.*allan"