- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep for multiple searches
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
Forums
Discussions
Discussions
Discussions
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
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
12-11-2007 05:52 AM
12-11-2007 05:52 AM
can I use a single grep for multiple searches on the same input line:
ftpelp1 pts/1
so I want all entries with ftpelp1 and Apr 27.
I know I can do
last|grep ftpelp1 |grep "Apr 27"
but can I do like in linux:
last |grep -e ftpelp1 -e "Apr 27"
thanks
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 05:56 AM
12-11-2007 05:56 AM
SolutionThe man page shows -e as a valid option in grep for patter matching.
Would it not be easier to just test it on HP-UX?
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 05:59 AM
12-11-2007 05:59 AM
Re: grep for multiple searches
with the help of -e option you can do multiple search.
Thanks,
Aneesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 06:04 AM
12-11-2007 06:04 AM
Re: grep for multiple searches
last | egrep "ftpelp1|Apr 27"
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 06:08 AM
12-11-2007 06:08 AM
Re: grep for multiple searches
...or use the '-E' option to enable extended regular expressions:
# last|grep -E "ftpelp1|Apr 27"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 06:58 AM
12-11-2007 06:58 AM
Re: grep for multiple searches
looks like grep does work slightly different from 1 OS to the next.
but some good examples here that I can adapt across AIX Linux Tru64 and HPUX.
cheers.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 11:50 AM
12-11-2007 11:50 AM
Re: grep for multiple searches
I know I can do
last|grep ftpelp1 |grep "Apr 27"
but can I do like in linux:
last |grep -e ftpelp1 -e "Apr 27"
"
no...No....NO!
the results of the above are entirely different from each other. You said: "so I want all entries with ftpelp1 and Apr 27."...not a really clear problem definition.
If you want a list of all lines containing both "ftpelp1" and "Apr 27", the use the code as noted in your first example above
I you want all lines containing either (or both) "ftpelp1" or "Apr 27", then the second is sufficient....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 05:49 PM
12-11-2007 05:49 PM
Re: grep for multiple searches
1) use -e for each
2) use -f and put them in a file
3) use a newline:
$ grep "foo
bar" file
If you want to use grep to do an AND you can use:
1) piped greps like you had.
2) big regular expressions:
$ grep "ftpelp1.*Apr 27"
If you want either order, you would need to use two -e with the words reversed.