Re: grep exact search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Re: grep exact search
# 1  
Old 09-12-2012
Re: grep exact search

Hi,

Code:
x=GATE

ps -ef|grep pmon
grid       552     1  0 Aug08 ?        00:00:51 asm_pmon_+ASM1
oracle    4314     1  0 Aug08 ?        00:04:08 ora_pmon_GATE1
oracle    5018  1351  0 10:14 pts/1    00:00:00 grep pmon
oracle    7329     1  0 Aug08 ?        00:02:19 ora_pmon_NRID1

ps -ef|grep pmon |grep $x
oracle    4314     1  0 Aug08 ?        00:04:08 ora_pmon_GATE1

but i want the result if it contains only GATE but not the GATE1

-Thanks,

Moderator's Comments:
Mod Comment edit by bakunin: corrected typo in thread title to make it better searchable

Last edited by bakunin; 09-12-2012 at 04:20 PM..
# 2  
Old 09-12-2012
try using grep $x$ if you are expecting GATE at the end of line..
This User Gave Thanks to vidyadhar85 For This Post:
# 3  
Old 09-12-2012
Belt and braces:
Code:
ps -fuoracle | grep -v "grep" | grep "pmon" | grep "GATE" | grep-v "GATE1"

It would be better as:
Code:
ps -fuoracle | grep -v "grep" | grep "ora_pmon_GATE" | grep -v "ora_pmon_GATE1"


Maybe consider changing the name of each listener?

Last edited by methyl; 09-12-2012 at 01:47 PM.. Reason: assorted typos
# 4  
Old 09-12-2012
I suggest you consult the man page of "grep", especially the meaning of the "-w" switch (word boundaries).

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To search exact pattern

Hi, I need to search the exact pattern in a file file.txt AUS.txt|AUS.chk NZ.txt|NZ.ch I am getting the result as AUS.txt|AUS.chk with below code but i need only AUS.txt to be printed grep AUS.txt file.txt CODE tags also for data files (8 Replies)
Discussion started by: rohit_shinez
8 Replies

2. UNIX for Dummies Questions & Answers

Grep exact value

Hello All, I have a file all_info.txt Date Owner Filename 03/25/2014 mycomp\royale myfile_ goodfile_sec_20140324_c.zip 03/25/2014 mycomp\royale myfile_goodfile_sec_20140324_c.cpt 03/25/2014 mycomp\royale1 ... (9 Replies)
Discussion started by: kumar30213
9 Replies

3. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

4. Shell Programming and Scripting

search and replace exact string

Hello Everyone, Im trying to run a search and replace of exact strings and the strings that im using variables that are passed through an array in a while loop. Here is a snip of my code: USEROLD=`cat oldusers` USERNEW=`cat newusers` USEROLDARRAY=( $USEROLD ) USERNEWARRAY=( $USERNEW )... (4 Replies)
Discussion started by: skizim
4 Replies

5. Shell Programming and Scripting

Exact Search and Replace using AWK

Hello. I have written the following script to search and replace from one file into another. #awk script to search and replace from file a in file b NR == FNR { A=$2; next } { for( a in A ) sub(a, A)}1 file2 file1 While the function works pretty well, I want a. The word in File 2 to... (8 Replies)
Discussion started by: gimley
8 Replies

6. Shell Programming and Scripting

How to grep the exact name?

I'm attempting to perform an exact match on an input data column with another input file but cannot figure out how to code the "grep" statement to handle 2 specific scenarios. I’m capturing the first column of data from $ifile2 into variable $rule and using it to perform a “grep” on $ifile3 to... (4 Replies)
Discussion started by: ltf1833
4 Replies

7. UNIX for Advanced & Expert Users

Search for an exact string in a Terminal

Is there hopefully a way to search for an exact string in Man Pages? I know if I want to search for anything containing -c I can just do this. /-c How would I search for "-c"? I want only "-c" to show up. So I tried this. /"-c" It took me literally and looked for the quotes also. (13 Replies)
Discussion started by: cokedude
13 Replies

8. Shell Programming and Scripting

Search for exact string

Hi All, I need to search in a csv file as mentioend in the Appendix A for a exact word lets "TEST". But using teh below command iam getting TEST1234, TEST12 and otehr entries as well. the problem is i check this condition to check to add a record to a table by making sure it does not... (16 Replies)
Discussion started by: rahman_riyaz
16 Replies

9. UNIX for Dummies Questions & Answers

grep exact string/ avoid substring search

Hi All, I have 2 programs running by the following names: a_testloop.sh testloop.sh I read these programs names from a file and store each of them into a variable called $program. On the completion of the above programs i should send an email. When i use grep with ps to see if any of... (3 Replies)
Discussion started by: albertashish
3 Replies

10. UNIX for Dummies Questions & Answers

grep - exact

I'm trying to use grep to search for a specific string. Given the following strings: .A BAGM4 0101 Z DH1300/PPD T/SF T/SD 10 .A CLUM4 0101 Z DH1300/PP T/SF T/SD 9 .A MQT 0101 Z DH1200/PPK T/SFK 2.0/SD 15 I only want to get the string that contains PPD. If I do the command: grep PPD... (9 Replies)
Discussion started by: wxornot
9 Replies
Login or Register to Ask a Question