1837523 Members
3547 Online
110117 Solutions
New Discussion

Re: grep

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

grep

How can I issue a ps -ef | grep junk
but not return the grep command?
As in

ps -ef | grep junk
root 6874 1501 0 10:15:33 pts/tb 0:00 grep junk
UNIX IS GOOD
7 REPLIES 7
Robert-Jan Goossens
Honored Contributor
Solution

Re: grep

Hi Robert,

# ps -ef | grep junk |grep -v grep

Robert-Jan.
Jairo Campana
Trusted Contributor

Re: grep

with:

ps -ef|grep junk |grep -v grep

option -v exclude
legionx
Pete Randall
Outstanding Contributor

Re: grep

Easy, just do this:

ps -ef | grep junk | grep -v "grep"


Or, better yet, put this little script called psg in /usr/local/bin:

##########################################################################
# psg - Process Search
# Substitute for "ps -ef|grep" command string.
##########################################################################
case $# in
0) echo "Error: Argument Expected";
exit;
;;
1) ps -ef | grep $1 | grep -v "grep"
# 1) UNIX95= ps -fC $1
;;
*) echo "Error: Only 1 Argument Allowed";
exit;
;;
esac

Then just do "psg junk"




Pete

Pete
John Poff
Honored Contributor

Re: grep

Hi,

One way to do it is like this:

ps -ef | grep [j]unk


But probably the better method is to use the XPG4 implementation of the 'ps' command to look for the actual command by using the '-C' option:

UNIX95=1 ps -fC junk

I like that because it is much cleaner and you don't have to invite grep to the party.

JP
Tom Danzig
Honored Contributor

Re: grep

Here's an alias you can put in your profile that works good:

alias psg='ps -ef | grep -v grep | grep -e PPID -e'
Steven E. Protter
Exalted Contributor

Re: grep

I have a script called psg, got it out of a book.

#!/usr/bin/sh
#
# Program name : psg
# Usage : psg some_pattern
# This program searches through a process status (ps -ef)
# listing for a pattern given as the first command line
# argument
procs=`ps -ef`
head=`echo "$procs" | line`

echo "$head"
echo "$procs" | grep -i $1 | grep -v $0 # Write out lines
# containing $1 but not thisprograms command line name

# Note that $procs MUSt be quoted or the newlines in the ps
# -ef listing will be turned into spaces when echoed. $head
# must also be quoted to preserve any extra whitespace

Lots of ways to get things done with Unix.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ravi_8
Honored Contributor

Re: grep

Hi,

ps -ef | grep junk | grep -v "grep"

sould do
never give up