how to exclude the GREP command from GREP


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users how to exclude the GREP command from GREP
# 1  
Old 10-04-2007
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  
Old 10-04-2007
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 06:19 PM..
# 3  
Old 10-05-2007
Quote:
Originally Posted by yamsin789
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude multiple lines using grep

Hi, I'm working on a shell script that reports service status on a database server. There are some services that are in disabled status that the script should ignore and only check the services that are in Enabled status. I output the service configuration to a file and use that information to... (5 Replies)
Discussion started by: senthil3d
5 Replies

2. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

3. Shell Programming and Scripting

Exclude dash in grep

Hi, I must be overlooking something, but I don't understand why this doesn't work. I'm trying to grep on a date, excluding all the lines starting with a dash: testfile: #2013-12-31 2013-12-31code: grep '^2013-12-31' testfileI'm expecting to see just the second line '2013-12-31' but I don't... (3 Replies)
Discussion started by: Subbeh
3 Replies

4. Shell Programming and Scripting

Grep for a srting & exclude two folders

Hi, Below is the command to grep for a string under grep -r "redeem" /home/tom Need to make it case insensitive and exclude logs & tmp folders under /home/tom directory in my Search. Need this in Linux. (1 Reply)
Discussion started by: mohtashims
1 Replies

5. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

6. Shell Programming and Scripting

Using Grep Include/Exclude Files

I wrote this korn script and ran into a hole. I can use find to exclude all the hidden directories and to use my include file/exclude files for running a full backup find / -depth -ipath '/home/testuser/.*' -prune -o -print| grep -f include.mydirs | grep -v -f exclude.mydirs but when I... (8 Replies)
Discussion started by: metallica1973
8 Replies

7. UNIX for Advanced & Expert Users

grep source code and exclude comments

I often find myself grepping source code for a variable name and many times the name would be present in comment lines that I 'd prefer not to see. Do you guys know any tricks to filter out comments? Example: snippet of the source code /*** * type comment 1 ***/ void ... (7 Replies)
Discussion started by: migurus
7 Replies

8. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

9. UNIX for Dummies Questions & Answers

grep exclude/find single and double quotes

Hello, I'm trying to use grep or egrep to exclude a whole range of characters but how do I exclude both a single and a double quote. It might be easier to say how do I use grep to find both single and double quotes. grep ' ' " ' file grep detects the first single quote within my... (4 Replies)
Discussion started by: Lindy_so
4 Replies

10. Shell Programming and Scripting

grep - to exclude lines beginning with pattern

11132 13069 11137 11142 13070 Can I use grep command to exclude all lines beginning with 13? I dont want to use grep -v 13 as potentially there will be a number with something like 11013 that I would exclude in error.. (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question