The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep exclude/find single and double quotes Lindy_so UNIX for Dummies Questions & Answers 4 03-06-2008 05:01 AM
grep command help geekeezoid UNIX for Dummies Questions & Answers 15 04-16-2007 08:55 PM
grep command mahabunta Shell Programming and Scripting 2 09-13-2006 12:11 AM
grep - to exclude lines beginning with pattern frustrated1 Shell Programming and Scripting 2 08-29-2005 04:18 AM
grep command ~ Need help april04 Shell Programming and Scripting 6 10-23-2002 12:57 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: Oct 2007
Posts: 7
Stumble this Post!
how to exclude the GREP command from GREP

I am doing "ps -f" to see my process.
but I get lines that one of it represents the ps command itself.
I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself :

I would like to exclude

[root@localhost ~]# ps -f
UID PID PPID C STIME TTY TIME CMD
root 15794 15792 0 13:48 pts/2 00:00:00 -bash
root 16157 15794 0 14:01 pts/2 00:00:00 ps -f

[root@localhost ~]# ps -f | grep -v ps
UID PID PPID C STIME TTY TIME CMD
root 15794 15792 0 13:48 pts/2 00:00:00 -bash
root 16160 15794 0 14:02 pts/2 00:00:00 -bash

while all I want is to get my pid line only.
or maybe you know another command that returns my pid and ppid only ?

thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-04-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
how 'bout
Code:
echo "myPID->[$$] PPID->[$PPID]"
or for Bourne shell (courtesy of USENET comp.unix.shell):
Code:
echo "myPID->[$$] PPID->[`ps -o ppid= -p $$`]"

Last edited by vgersh99; 10-04-2007 at 02:19 PM.
Reply With Quote
  #3 (permalink)  
Old 10-04-2007
Registered User
 

Join Date: May 2007
Posts: 111
Stumble this Post!
Quote:
Originally Posted by yamsin789 View Post
I am doing "ps -f" to see my process.
but I get lines that one of it represents the ps command itself.
I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself :

I would like to exclude

[root@localhost ~]# ps -f
UID PID PPID C STIME TTY TIME CMD
root 15794 15792 0 13:48 pts/2 00:00:00 -bash
root 16157 15794 0 14:01 pts/2 00:00:00 ps -f

[root@localhost ~]# ps -f | grep -v ps
UID PID PPID C STIME TTY TIME CMD
root 15794 15792 0 13:48 pts/2 00:00:00 -bash
root 16160 15794 0 14:02 pts/2 00:00:00 -bash

while all I want is to get my pid line only.
or maybe you know another command that returns my pid and ppid only ?

thanks
I wonder ,Which flavor of Unix you use ? in the following example it is working:

Code:
[root@dns ~]# uname -a
Linux dns 2.6.22.5-76.fc7 #1 SMP Thu Aug 30 13:47:21 EDT 2007 i686 athlon i386 GNU/Linux
[root@dns ~]# ps -f | grep -v ps
UID        PID  PPID  C STIME TTY          TIME CMD
root      2593  2572  0 Oct04 pts/1    00:00:00 -bash
also works in HP Unix,
can you check this out:

[root@dns ~]# ps -f | grep -v ps |grep -v grep
UID PID PPID C STIME TTY TIME CMD
root 2593 2572 0 Oct04 pts/1 00:00:00 -bash
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0