- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep 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
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
06-21-2005 02:41 AM
06-21-2005 02:41 AM
SVR
SVR1
SVR2
SVR4
SVR5
How to grep "SVR" so that it returns only
SVR ? Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:44 AM
06-21-2005 02:44 AM
Re: grep question
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
06-21-2005 02:48 AM
06-21-2005 02:48 AM
Re: grep question
grep -E -e '^SVR$' but since you are grepping the output of ps I would look for ' SVR ' (spaces surrounding the pattern).
ps -ef | grep -v grep | grep -E -e ' SVR '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:49 AM
06-21-2005 02:49 AM
Re: grep question
I'm not sure that you can do this with grep.
If you are sure that the pattern there is on the end of string, you can use SVR$, or, if you are sure that after the pattern there is a space, use "SVR ".
IMHO, the best way is
ps -ef |awk '$8=="SVR" {print}'
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:51 AM
06-21-2005 02:51 AM
Re: grep question
if the suffix is always going to benumerals, this should do the trick.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:52 AM
06-21-2005 02:52 AM
Re: grep question
ps -ef | grep -x SVR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:54 AM
06-21-2005 02:54 AM
Re: grep question
in any case, I think you want something like:
grep -e "SVR[[:space:]]" -e "SVR$"
at the end of your command - this will prevent SVR1, SVR2, etc., from being displayed. this searches for SVR followed by either whitespace or end-of-line, which should get you what you want. it won't prevent something like ASVR or BSVR, however, but I'm guessing that won't be an issue in your case.
--Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:54 AM
06-21-2005 02:54 AM
Re: grep question
The switch -x works for exact string, i.e if you have only SVR in the string. For a string, which contain SVR as a word -x does not work. 8((((
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:57 AM
06-21-2005 02:57 AM
Re: grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 02:57 AM
06-21-2005 02:57 AM
Re: grep question
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 03:34 AM
06-21-2005 03:34 AM
Re: grep question
ps -ef | grep -v grep | grep "SVR" | grep -v SVR[0-9]
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 04:11 AM
06-21-2005 04:11 AM
Re: grep question
ps -ef |grep SVR |head -1
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 05:23 AM
06-21-2005 05:23 AM
Solution# grep -w SVR
-w, --word-regexp force PATTERN to match only whole words
Get GNU grep if you don't have it yet!
Get GNU grep if you don't have it yet!
Get GNU grep if you don't have it yet!
Enjoy, Have FUN! H.Merijn
PS. If you build it yourself from scratch, install pcre first, and you get a grep that optionally supports Perl Compatible Regular Expressions!
Enjoy, Have More FUN! (TM) H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 06:12 AM
06-21-2005 06:12 AM
Re: grep question
UNIX95= ps -fC SVR
Type the command as shown. The UNIX95= is a one line method to set a variable temporarily. In the man page for ps, you'll see a number of options (-C -H -o) that are "XPG4" options. But they are disabled when UNIX95 does not exist. You don't want to set UNIX95 on a separate line as it affects other commands and libraries. So use the above example to find just SVR (or just SVR1, etc). The -C is an exact process name match built into ps.
A good rule of thumb is to always avoid using grep and ps together. If you need to find a list of processes by PID, use the -p option. Processes by owner: -u option. Create a customized output from ps: use -o
Here's a command line that shows only processes named sh (not ksh, not csh, not hasdaemon, not username trish, etc) and shows just user, PID and PPID, process size in Kbytes, and the command line for each process:
UNIX95= ps -C sh
UNIX95=
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 06:17 AM
06-21-2005 06:17 AM
Re: grep question
UNIX95= ps -C sh -o user,pid,ppid,vsz,args
The reason that grep fails is that it has no concept of field matching...it's just a left to right comparison on each line.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 09:10 AM
06-21-2005 09:10 AM
Re: grep question
ps -fe | perl -ane 'print if ( ! m/perl.*SVR[0-9]*/ && (m/SVR[0-9]*/ || m/PID/ ))'
UID PID PPID C STIME TTY TIME COMMAND
kilbours 25025 1 0 May 5 ? 0:00 SVR
kilbours 10393 1 0 Mar 1 ? 0:00 SVR1
kilbours 10393 1 0 Mar 1 ? 0:00 SVR199
kilbours 10393 1 0 Mar 1 ? 0:00 SVR0
A few pointers about how flexible perl is ".*" mean match anything 0 or more times "[0-9]*" means match any number 0 or more times. So the above says
o ! m/perl.*SVR[0-9]* DONT print if there is a line that starts perl and has SVR after it so ???perlSVR??? would do, and so would perl xxxxxxxxx 1234 SVR yyyy etc.
o m/SVR[0-9]*/ DO print if you see a line with SVR ending with any number of numerals e.g ???SVR??? or ????SVR0???? or ???SVR1???
o m/PID/ Do print if you see a line with PID in it (the headder for example)
Regards
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2005 09:23 AM
06-21-2005 09:23 AM
Re: grep question
# ps -fe | perl -ane 'print if ( ! m/perl.*SVR// && m/\bSVR\b/)'
kilbours 25025 1 0 May 5 ? 0:00 SVR
This will work, but it will also match "SVR -o multithread", but NOT "SVR1 -o multithread" If you also want to get rid of the "-o multithread" bit then
# ps -fe | perl -ane 'print if ( ! m/perl.*SVR/ && m/\bSVR$/)'
It is also usual to only want, say the PID & cmd for this you can use
ps -fe | perl -ane 'print "$F[1] $F[-1]\n " if ( ! m/perl.*SVR/ && m/\bSVR$/ )'
Regards
Tim