Showing results for 
Search instead for 
Did you mean: 

simple grep query

Go to solution
HP System Handle Owner
Occasional Advisor

simple grep query

Hi there

I've got two processes running both concerning TSM.

One process is

root 659500 1 0 Aug 01 - 0:00 /usr/tivoli/tsm/client/ba/bin/d
smcad -optfile=/file1

The other is

root 659500 1 0 Aug 01 - 0:00 /usr/tivoli/tsm/client/ba/bin/d
smcad.shared -optfile=/file1

I want to be able to grep for 'dsmcad' for the first one, or 'dsmcad.' for the second one

i.e. How to run grep and have them pick up ONE of the entries only

ps -ef | grep "dsmcad." picks up both

Thanks in advance

Not another questionnaire !!
Ralph Grothe
Honored Contributor

Re: simple grep query


UNIX95= ps -o pid= -C dsmcad


UNIX95= ps -o pid= -C dsmcad.shared
Madness, thy name is system administration
Simon Hargrave
Honored Contributor

Re: simple grep query


ps -ef | grep "dsmcad\."

You need to escape the "." since in regular expressions . means "any single character" so it is matchnig the space in the "smcad " line. The escape means look literally for the "."
Andrew Merritt_2
Honored Contributor

Re: simple grep query

ps -ef | grep 'dsmcad[^.]'
will match the first
ps -ef | grep 'dsmcad\.'
will match the second
Pedro Cirne
Esteemed Contributor

Re: simple grep query



ps -ef|grep "dsmcad " don't forget the blank space .-)


ps -ef|grep "dmscad."

Enjoy :)

Bill Hassell
Honored Contributor

Re: simple grep query

As you have seen, grep is a very poor tool to use with ps, especially because ps has exact match capability built-in. You use the -C option for an exact match to the process name. But the -C option (and -H and -o, etc) are not available unless you enable (temporarily) the XPG4 behavior using UNIX95. This will give an exact match for either process:

UNIX95= ps -fC dsmcad
UNIX95= ps -fC dsmcad.shared

Although the UNIX95= looks strange, this is how you define a temporary variable for the name process. Don't set or export UNIX95 in your shell, just use it on the command line as shown.

Bill Hassell, sysadmin