Sponsored Content
Top Forums UNIX for Advanced & Expert Users how to exclude the GREP command from GREP Post 302139251 by xramm on Friday 5th of October 2007 02:59:40 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
PS(1)							      General Commands Manual							     PS(1)

NAME
ps - process status SYNOPSIS
ps [-alxU] [kernel mm fs] OPTIONS
-a Print all processes with controlling terminals -l Give long listing -x Include processes without a terminal EXAMPLES
ps -axl # Print all processes and tasks in long format DESCRIPTION
Ps prints the status of active processes. Normally only the caller's own processes are listed in short format (the PID, TTY, TIME and CMD fields as explained below). The long listing contains: F Kernel flags: 001: free slot 002: no memory map 004: sending; 010: receiving 020: inform on pending signals 040: pending signals 100: being traced. S State: R: runnable W: waiting (on a message) S: sleeping (i.e.,suspended on MM or FS) Z: zombie T: stopped UID, PID, PPID, PGRP The user, process, parent process and process group ID's. SZ Size of the process in kilobytes. RECV Process/task on which a receiving process is waiting or sleeping. TTY Controlling tty for the process. TIME Process' cumulative (user + system) execution time. CMD Command line arguments of the process. The files /dev/{mem,kmem} are used to read the system tables and command line arguments from. Terminal names in /dev are used to generate the mnemonic names in the TTY column, so ps is independent of terminal naming conventions. PS(1)
All times are GMT -4. The time now is 09:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy