grep multiple words in a single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep multiple words in a single line
# 1  
Old 01-27-2009
grep multiple words in a single line

Hi..
How to search for multiple words in a single line using grep?.

Eg: Jack and Jill went up the hill
Jack and Jill were best friends
Humpty and Dumpty were good friends too
----------

I want to extract the 2nd statement(assuming there are several statements with 'friends' pattern)..so I want to match the all the patterns
like 'Jack', 'Jill' and 'friends'

Thx !
Anduzzi
# 2  
Old 01-27-2009
You have to use egrep for that, for ex:
egrep -e "Jack|Jill|friends"
# 3  
Old 01-27-2009
you can use awk also
Code:
awk '/Jack/&&/Jill/&&/friends/{print $0}' filename

# 4  
Old 01-27-2009
Quote:
Originally Posted by just4fundoit
You have to use egrep for that, for ex:
egrep -e "Jack|Jill|friends"
this will give the lines containing Jack or Jill or friends
i don't think anduzzi want that
# 5  
Old 01-27-2009
Hi

Hi guys...thx for the responses...really appreciate !
But none is working in my scenario..
well here is what I have practically:

mp ifile PDEWS001.S1_C1_Dim_Input_File 'file:'"${INPUT}"'/ssim_svc_type.csv'

mp ifile PDEWS001.S2_C4_CURRENT 'file:'"${DATA}"'/'"${AB_GRAPH_NAME}"'_s2_c4_current.dat'

well....I don't want the second line here...I just need the entire line that has the combination of both 'ifile' and 'INPUT' but not 'ifile' and 'DATA'.
I tried both of the above suggested egrep and awk and it doesnt work.

please suggest !
-Anduzzi
# 6  
Old 01-27-2009
Well you could do some thing like
awk '/ifile/&&/INPUT/ {print $0}' FILENAME|grep -v DATA
# 7  
Old 01-27-2009
Quote:
Originally Posted by just4fundoit
Well you could do some thing like
awk '/ifile/&&/INPUT/ {print $0}' FILENAME|grep -v DATA
no need for 'grep' and 'print $0':
Code:
awk '/ifile/&&/INPUT/ && !/DATA/' FILENAME

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Display multiple words into a single td tag

awk 'BEGIN{print "<table>"} {print "<tr>"; for ( i=1;i<NF;i++) print " <td>" $I "</td>"; print "</tr>"} END{print " </table>"}' <file name > (6 Replies)
Discussion started by: Himanshu1
6 Replies

2. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

3. Shell Programming and Scripting

Confused with grep for multiple words

Hi guys and gals, I have many files that contains many lines of data. I am trying to find a needle in a haystack in that I'm looking only for files that contain word1 AND word2. I'm using ... ... but this is finding files that contains word1 OR word2. No good for me. How can I grep to... (7 Replies)
Discussion started by: bbbngowc
7 Replies

4. Shell Programming and Scripting

Grep multiple words with not null value

Hi, I want to grep a file if any one (GH, IJ, KL) is not null. If it is null i dont want to pull anything. cat file | awk '{print ($1)}' Parameters are : AB=123;CD=456;EF=6789; cat file | awk '{print ($2)}' GH=456;IJ=789;KL=1011 eg: Contents in file: Parameters are :... (10 Replies)
Discussion started by: Neethu
10 Replies

5. Shell Programming and Scripting

Grep multiple words in a single file

Hello All, I'm a newbie/rookie in Shell scipting. I've done oracle export of a table using Export utility. When I do export, it generates 2 files. 1> .dmp file 2> .dmp.log file. In .dmp.log file I have to search for a sentence which goes like '0 records have been inserted' and then... (2 Replies)
Discussion started by: samfisher
2 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. UNIX for Dummies Questions & Answers

extract text between two words on a single line

Hi Guys, Can someone help me with a way to extract text between two words on a single line. For example if the file has below content I want to extract all text between b and f inclusive of b and f. Aparently sed does this but does it line by line and I guess it cannot read word by word. ... (11 Replies)
Discussion started by: krishnaux
11 Replies

8. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

9. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

10. 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
Login or Register to Ask a Question