- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Exact word search using grep
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
тАО05-21-2008 07:58 AM
тАО05-21-2008 07:58 AM
I am trying to search a word and greping the output of "ps -ef|grep someword".
This grep also gives the result someword,somwordxxx, and somewordabc etc which i do not want.
Can someone suggest how to grep exact word from the output of ps -ef ?
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2008 08:06 AM
тАО05-21-2008 08:06 AM
SolutionIf you want to match "words" with 'grep' then use the '-w' switch.
That said, if the question is really about matching a process from 'ps', use the UNIX95 (XPG4) options like:
# UNIX95= ps -C cron
Note the whitespace after 'UNIX95='. This arms the behavior only for the duration of the commandline.
You can also add options to your taste:
# UNIX95= ps -C cron -o pid,ppid,args,etime
PID PPID COMMAND ELAPSED
1780 1 /usr/sbin/cron 78-17:21:06
Regards!
...JRF...
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2008 10:52 AM
тАО05-21-2008 10:52 AM
Re: Exact word search using grep
around it, then search for "someword" with
white space around it:
[...] | grep ' someword '
If tabs are possible as well as spaces, then
you'll need to work a little harder, but not
much harder.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-21-2008 11:43 PM
тАО05-21-2008 11:43 PM
Re: Exact word search using grep
even if the best option is to use UNIX95 as already suggested a trick for you is to use:
ps -ef|grep [s]omeword
this will avoid you to add | grep -v grep to esclude the grep command itself from your ouput list.
Just my .02$
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2008 04:10 AM
тАО05-22-2008 04:10 AM
Re: Exact word search using grep
Clever. Spaces work in there, too:
[...] | grep ' [s]omeword '
Of course, if "someword" is a variable, this
all gets harder to do.
(And if you're looking for a program name
with no arguments in "ps" output, then you
may not want that last space. If you're
looking for a UID, then you probably do.)