Grep multiple exact match, do not display lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep multiple exact match, do not display lines
# 1  
Old 10-25-2013
Grep multiple exact match, do not display lines

Hi,

Need help to grep the following from a file x. I just want to grep exact match not lines and not partial word.

Code:
CONFSUCCESS
CONFFAIL
CONFPARTIALSUCCESS

Code:
>cat x
xczxczxczc zczczcxx CONFSUCCESS czczczcczc
czxxczxzxczcczc CONFFAIL xczxczcxcczczc
zczczczcz CONFPARTIALSUCCESS czczxcxzc

i tried this

Code:
grep -w "CONFSUCCESS\|CONFFAIL\|CONFPARTIALSUCCESS" x

also this, getting only matching words not the whole word

Code:
grep -o "CONF*" x
CONF
CONFF
CONF

Want result as below

Code:
CONFSUCCESS
CONFFAIL
CONFPARTIALSUCCESS

Thanks
Moderator's Comments:
Mod Comment CODE tags are used to mark sample code segments, sample input data, and sample output data; not your entire message.

Last edited by Don Cragun; 10-25-2013 at 09:39 PM.. Reason: Fix CODE tags.
# 2  
Old 10-25-2013
Code:
grep -o "CONF[^ ]*" x


Last edited by Yoda; 10-25-2013 at 06:42 PM.. Reason: correction in regex
This User Gave Thanks to Yoda For This Post:
# 3  
Old 10-25-2013
Try for printing words

Code:
$ grep -o 'CONFSUCCESS\|CONFFAIL\|CONFPARTIALSUCCESS' file

OR

Code:
$ egrep -wo 'CONFSUCCESS|CONFFAIL|CONFPARTIALSUCCESS' file

# 4  
Old 01-21-2014
another awk approach for same.


Input is as follows.

Code:
xczxczxczc zczczcxx CONFSUCCESS czczczcczc
czxxczxzxczcczc CONFFAIL xczxczcxcczczc
zczczczcz CONFPARTIALSUCCESS czczxcxzc


Code:
awk '{for(i=0;i<=NR;i++) {for(i=1;i<=NF;i++) {if($i=="CONFSUCCESS" || $i=="CONFFAIL" || $i =="CONFPARTIALSUCCESS")  print $i}}}' file_name

Output will be as follows.

Code:
CONFSUCCESS
CONFFAIL
CONFPARTIALSUCCESS


Thanks,
R. Singh
# 5  
Old 01-21-2014
Another approach:

Code:
grep -ow "CONF\w*" x

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep for an exact match in a file

I am currently having some issues while trying to grep for a exact string inside a file. I have tried doing this from command line and things work fine i.e. when no match is found, return code=1 but when its done as part of my script it returns 0 for the same command - I dont know if there is an... (6 Replies)
Discussion started by: Ads89
6 Replies

2. Shell Programming and Scripting

Grep and display multiple lines

Hi guys, I have a log file that generates multiple logs about a query. <query time='2016-04-13 13:01:50.825'> <PagingRequestHandler> <Before>brand:vmu</Before> <After>brand:vmu</After> </PagingRequestHandler> <GroupDeviceFilterHandler> <Before>brand:vmu</Before> ... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

3. Shell Programming and Scripting

Grep exact match

Hello! I have 2 files named tacs.tmp and tacDB.txt tacs.tmp looks like this 0 10235647 102700 106800 107200 1105700 tacDB.txt looks like this 100100,Mitsubishi,G410,Handheld,,0,0,0 100200,Siemens,A53,Handheld,,0,0,0 100300,Sony Ericsson,TBD (AAB-1880030-BV),Handheld,,0,0,0... (2 Replies)
Discussion started by: Cludgie
2 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Grep multiple files and display first match

I have a need to grep a large number of files, but only display the first result from each file. I have tried to use grep, but am not limited to it. I can use perl and awk as well. Please help! (9 Replies)
Discussion started by: dbiggied
9 Replies

5. Shell Programming and Scripting

Searching for exact match using grep

I am searching for an exact match on a value read from another file to lookup an email address in another file. The file being checked is called "contacts" and it has Act #, email address, and contact person. 1693;abc1693@yahoo.comt;Tommy D 6423;abc6423@yahoo.comt;Jim Doran... (2 Replies)
Discussion started by: ziggy6
2 Replies

6. Shell Programming and Scripting

Grep two words with exact match

HI Input : Counters Counter Int Ints Counters Counters Ints Ints I want to grep Counter|Int Output : Counter (1 Reply)
Discussion started by: pareshkp
1 Replies

7. Solaris

grep exact match

Hi This time I'm trying to grep for an exact match e.g cat.dog.horse.cow.bird.pig horse.dog.pig pig.cat.horse.dog horse dog dog pig.dog pig.dog.bird how do I grep for dog only so that a wc -l would result 2 in above case. Thanks in advance ---------- Post updated at 06:33 AM... (4 Replies)
Discussion started by: rob171171
4 Replies

8. Shell Programming and Scripting

shell script: grep multiple lines after pattern match

I have sql file containing lot of queries on different database table. I have to filter specific table queries. Let say i need all queries of test1,test2,test3 along with four lines above it and sql queries can be multi lines or in single line. Input file contains. set INSERT_ID=1; set... (1 Reply)
Discussion started by: mirfan
1 Replies

9. UNIX for Dummies Questions & Answers

Grep and display n lines after the match is found.

Hello, How do I use grep to find a pattern in a list of file and then display 5 lines after the pattern is matched Eg: I want to match the string GetPresentCode in all files in a folder and then see 4 lines following this match. I am not sure if grep is what should be used to achieve. Thanks!... (3 Replies)
Discussion started by: cv_pan
3 Replies

10. UNIX for Advanced & Expert Users

Exact Match thru grep ?????

hey..... i do have text where the contents are like as follows, FILE_TYPE_NUM_01=FILE_TYPE=01|FILE_DESC=Periodic|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=B FILE_TYPE_NUM_02=FILE_TYPE=02|FILE_DESC=NCTO|FILE_SCHDL_TYPE=Daily|FILE_SCHDL=|FILE_SCHDL_TIME=9:00am|RESULTS=M... (2 Replies)
Discussion started by: manas_ranjan
2 Replies
Login or Register to Ask a Question