Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grepping with ps

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
If you use "ps -ef" and grep for a certain command how can you get the display to NOT show the grep command too?

Example: ps -ef|grep foo

It will of course show all the processes using "foo" but how can I filter out the grep process for foo from the output?

Thanks very much for your time guys,

Michael

 
ps -ef|grep foo|grep -v grep Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Here's a related script I use to see all my (the user) processes without seeing the ps, script, and the associated awk commands.

This works in any shell for my version of HP-UX but will have to be tweaked for other shells and OS. No guarentees here.

#! /bin/sh
CMD=`basename $0`
ps -eaf | awk '
{
if(/'"`whoami`"'/){
if( $8 ~ /'"$CMD"'/ ){
cmd_pid=$2
nopr_cmd=i
}
line[i++]=$0
}
}
END {
printf( "%6s %-9s %4s %s\n", "PID", "TTY", "TIME", "COMMAND" )
for(j=0;j<i;j++){
$0=line[j]
# a(b+c)(d+c) -> a(c+bd)
if( j != nopr_cmd && ($3 != cmd_pid ||
($8 != &quot;awk&quot; && $8 != &quot;ps&quot; ))){
printf( &quot;%6s %-9s %4s %s\n&quot;, $2, $6, $7, substr($0,
idx=index($0, $8),
length($0) - idx + 1))
}
}
}'


Cheers,
ND

 
All these suggestions on grep where great and helped me very much.

Thanks for you time guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top