greping out multiple words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting greping out multiple words
# 1  
Old 08-20-2006
greping out multiple words

now i have a lot of words i need to grep out of a certain line but i have to keep typing this:


ex

ls -l | grep -v this | grep -v that | grep -v those | grep -v them .....


i mean, it goes on like that. there has to be a way to grep all those words without having to specify that "grep -v"

does anyone know how to do this?
Terrible
# 2  
Old 08-20-2006
Quote:
Originally Posted by Terrible
now i have a lot of words i need to grep out of a certain line but i have to keep typing this:


ex

ls -l | grep -v this | grep -v that | grep -v those | grep -v them .....


i mean, it goes on like that. there has to be a way to grep all those words without having to specify that "grep -v"

does anyone know how to do this?
I dont have access to a unix box right now. But there is a -E flag. Try grep -vE (this|that|those|them)
# 3  
Old 08-20-2006
grep available in /usr/bin/grep doesnt have the -E option

make use of the grep in
Code:
/usr/xpg4/bin/grep -E 'some1|some2' filename

# 4  
Old 08-20-2006
Quote:
Originally Posted by matrixmadhan
grep available in /usr/bin/grep doesnt have the -E option

make use of the grep in
Code:
/usr/xpg4/bin/grep -E 'some1|some2' filename


thanks guys. but i need to grep out quite more than 2 words. will the above suffice?
Terrible
# 5  
Old 08-20-2006
yes very much...

just extend the list delimited by '|'
# 6  
Old 08-20-2006
U can use egrep

To grep multiple words in file, u can use egrep.

/uday> egrep 'word1|word2|word3|word4' filename

Uday
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

2. Shell Programming and Scripting

How to replace multiple words together?

I am looking for any smart perl solution for multiple word replacement together. My awk is working but for big files it is superslow. awk 'NR==FNR {a=$2;next} {for ( i in a) gsub(i,a)}1' new_word_list.txt oldfile > newfile new_word_list.txt looks like AB733 ST756 AB734 ST219 AB11 ... (4 Replies)
Discussion started by: sammy777888
4 Replies

3. Shell Programming and Scripting

Find Multiple words in a file

Hi all, I have trouble in finding the multiple word in .txt file. Please help me with any solution. I have 10,000 .txt files and in each file i have to search specific word but more than one, like (data, machine learning, clustering) and all these keywords should be case insensitive because... (3 Replies)
Discussion started by: XXLMMN
3 Replies

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

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

6. Shell Programming and Scripting

Bringing together words from multiple lines

I want to get a file together that lists router name and IP address of an interface together like so... SOMERTR1A 10.10.10.20 SOMERTR1B 10.10.10.30 OTHRRTR1A 192.168.1.120 The file I'm trying to extract the text from looks like the below: SOMERTR1A#show run int Lo0 | i add ... (5 Replies)
Discussion started by: branrobi
5 Replies

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

8. Shell Programming and Scripting

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... (11 Replies)
Discussion started by: anduzzi
11 Replies

9. UNIX for Dummies Questions & Answers

Testing for multiple words in a Variable

Hi, Been mulling this one over today and can't seem to find the exact method to solve this. So I assign a value to a variable based on a grep. Usually that variable has 1 value but today I realized that depending on the text I parse, it might get 2 or 3 or more. The result comes out like the... (1 Reply)
Discussion started by: eltinator
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