The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 09:01 AM
grep command help geekeezoid UNIX for Dummies Questions & Answers 15 04-16-2007 11:55 PM
grep command mahabunta Shell Programming and Scripting 2 09-13-2006 03:11 AM
grep - to exclude lines beginning with pattern frustrated1 Shell Programming and Scripting 2 08-29-2005 07:18 AM
grep command ~ Need help april04 Shell Programming and Scripting 6 10-23-2002 03:57 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-04-2007
yamsin789 yamsin789 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 7
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
  #2 (permalink)  
Old 10-04-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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 05:19 PM..
  #3 (permalink)  
Old 10-05-2007
xramm xramm is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0