multiple search keyword in grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple search keyword in grep
# 8  
Old 03-17-2009
Hi Summer, actually you are rite. But what I am seeking for is the previous example.if A: and D: both are found in a line it needs to be shown.
# 9  
Old 03-18-2009
This one may help your need

awk '{if(/A/) {if(/D/) print $0 }}' inputfilename

Thanks
Sha
# 10  
Old 03-19-2009
file contains
A:T00 B:88 C:78 D:00
A:Y00 B:88 C:78
A:T00 B:88 C:78 D:60
A:T00 B:88 C:78

bash-2.05$ awk '{if(/A/) {if(/D/) print $0 }}' multigrep.txt
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1
# 11  
Old 03-19-2009
Quote:
Originally Posted by Shahul
This one may help your need

awk '{if(/A/) {if(/D/) print $0 }}' inputfilename

Thanks
Sha
no need explicit "if"s
Code:
awk '/A/ && /D/' file

# 12  
Old 03-19-2009
Hi,

In my System its working good.. Smilie
see my output:
$ cat out.lst
A:T00 B:88 C:78 D:00
A:Y00 B:88 C:78
A:T00 B:88 C:78 D:60
A:T00 B:88 C:78

Code:
$ awk '{if(/A/) {if(/D/) print $0 }}' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60

Or you can use below one as well..

Code:
$ sed -n '/A.*D/p' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60

Code:
$ sed '/A.*D/!d' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60

Code:
$ sed '/A/!d; /D/!d' out.lst
A:T00 B:88 C:78 D:00
A:T00 B:88 C:78 D:60


Thanks
Sha

Last edited by Shahul; 03-19-2009 at 07:46 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Linux

How to search multiple word using grep command?

How to search multiple word using grep command for example i want to reserch ANJ001 AA Using ridiculous font, size, and color changes instead of normal space separated text and CODE tags obfuscates what you are trying to do and makes it difficult for volunteers who may want to help you solve... (1 Reply)
Discussion started by: na.dharma
1 Replies

3. Shell Programming and Scripting

Search for a Keyword in file and replace another keyword or add at the end of line

Hi I want to implement something like this: if( keyword1 exists) then check if(keyword2 exists in the same line) then replace keyword 2 with New_Keyword else Add New_Keyword at the end of line end if eg: Check for Keyword JUNGLE and add/replace... (7 Replies)
Discussion started by: dashing201
7 Replies

4. Shell Programming and Scripting

Whether we can search multiple strings using or in grep -F

Hi, Whether we can search multiple strings using or in grep -F In Generally, grep -F "string1" "filename.txt" How to search for multiple string using grep -F as we using grep grep "string1\|string2" "filename.txt" Regards, Nanthagopal A (10 Replies)
Discussion started by: nanthagopal
10 Replies

5. Shell Programming and Scripting

Grep multiple search terms with context

I have a file that is a sort library in the format: ##def title1 content1 stuff1 content2 stuff2 ##enddef ##def title2 etc.. I want to grep def and content and pull some trailing context from content so the result would look something like: (1 Reply)
Discussion started by: Moe.Wilensky
1 Replies

6. Shell Programming and Scripting

Help to search multiple pattern in file with grep/sed/awk

Hello All, I have a file which is having below type of data, Jul 19 2011 | 123456 Jul 19 2011 | 123456 Jul 20 2011 | 123456 Jul 20 2011 | 123456 Here I wanted to grep for date pattern as below, so that it should only grep "Jul 20" OR "Jul ... (9 Replies)
Discussion started by: gr8_usk
9 Replies

7. UNIX for Dummies Questions & Answers

Multiple Line search using grep

Hi All, I am trying to search multiple lines in file using grep /sed.And i cant seem to make it work. The File looks like this 5012001,100,AUTOBATCH,FEE,DAILYFEE,0,0 4241 SERVICE DENIED 5012002,100,AUTOBATCH,FEE,DAILYFEE,0,0 4241 SERVICE DENIED... (6 Replies)
Discussion started by: pistachio
6 Replies

8. UNIX for Dummies Questions & Answers

search multiple words using grep

Hi frnds i want to desplay file names that should be word1 and word2 ex : i have 10 *.log files 5 files having word1 and word2 5 files having only word1, i have used below command egrep -l 'word1|word2' *.log its giving all 10 files, but i want to display only 5... (20 Replies)
Discussion started by: pb18798
20 Replies

9. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies

10. Shell Programming and Scripting

multiple search with grep

is it possible to execute multiple search with grep??? grep criteria1 criteria2 file something like this... I know other way: grep pattern1 file-name1 > results-file grep pattern2 file-name1 >> results-file cat results-file but can it be done with one grep???? (5 Replies)
Discussion started by: amon
5 Replies
Login or Register to Ask a Question