How to grep more then one word?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to grep more then one word?
# 1  
Old 10-17-2002
How to grep more then one word?

I need to find in a given file (text) all lines containing the word 'bla' AND all lines containing the word 'blue' and so on...
The following command is not good because it gives the lines containing all words:
cat text | grep bla | grep blue

Thanx
8-)

http://www.geocities.com/cohvi
# 2  
Old 10-17-2002
Try this

cat <file> | grep -i -E "xls|jpg|bmp|doc|etc"
# 3  
Old 10-17-2002
cat is unnecessary. You can do it this way

grep -E "one|two|three" file.txt

With cat you must read the entire file first and then direct the output to the grep. If you have a small file this is fine, but if you have a very large file, say 1mb or more, like as in a log file, it will have a delay and take time away from your other application processes since 50% of all time slices are reserved for the OS and root, at least on HPUX that is the way it is.
# 4  
Old 10-17-2002
root@catty:[130] >uname -a
SunOS catty 5.8 Generic_108528-13 sun4u sparc SUNW,Ultra-2
root@catty:[131] >grep -E "test" *
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
root@catty:[132] >
# 5  
Old 10-18-2002
Champ, this is a forum you can add commentary. Smilie You might need to download a newer version of grep for your sparc. Most modern versions of grep support -E.

Of course, your version of UNIX must support the -E option. If you don't have it you must use either:

egrep or

grep -e text -e "text" file.out


Smilie
# 6  
Old 10-18-2002
On SunOS, /usr/xpg4/bin/grep is a modern grep that supports -E.
 
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 a word or word with underscore

I have a file "test" with following contents: cat test abc abcd_efg abc_abc I want to only grep for abc or abc_ without getting other results, how do I achieve this? If I use grep -w abc test option I get only abc and not abc_. If I use egrep "abc|abc_" test its still printing... (3 Replies)
Discussion started by: ctrld
3 Replies

2. Shell Programming and Scripting

Need a word which just comes next to after grep of a specific word

Hi, Below is an example : ST1 PREF: int1 AVAIL: int2 ST2 PREF :int1 AVAIL: int2 I need int1 to come in preferred variable while programming and int2 in available variable Please help me doing so Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

3. Shell Programming and Scripting

Grep two word and one word with if

so far I have the following , it work, if grep -w "Hi"\|"Hello" /home/my.log 2>&1 > /dev/null then EMAIL_ADDR="aaa@gmail.com" echo "Please view the error messages on attached file " | mutt -a ~/error_report.txt -s "hi `date +"%d-%m-%Y"`" "$EMAIL_ADDR" fi But :(I want to add if... (6 Replies)
Discussion started by: Hscript
6 Replies

4. Shell Programming and Scripting

How ti Grep for a word and print the next word

Hi can we grep for a word and print the next word of the greped word? ex:- create or replace function function_name create function function_name we should search for word "function" and output next word "function_name" from both lines. (3 Replies)
Discussion started by: manasa_vs
3 Replies

5. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

6. Shell Programming and Scripting

How to grep a word and next column to that word?

Hi, I have input file as below. Can you help me? inac_4y;0;2;Balance;200;1;1; 0;2;Balance;100;1; 0;inac_nq;0;1;Balance;100;1 desired output Balance;200 Balance;100 Balance;100 -Suresh Please use and tags when posting code, data or logs etc. to preserve formatting... (5 Replies)
Discussion started by: suresh3566
5 Replies

7. Shell Programming and Scripting

Grep for a particular word and get only the word

HI, Let us a consider i have a file as following. abcde (flag5 / 234 ) Mod 45 efgh afghd (flag3/ 343) MOD 34 ghdd tryd (t_flag6/ 567 ) MOD 43 uifudiu Is there a way where I need only the flag and the calculation done on it. The output should be : (flag5 / 234 ) Mod 45 ... (8 Replies)
Discussion started by: ashwin3086
8 Replies

8. Shell Programming and Scripting

Grep out specific word and only that word

ok, so this is proving to be kind of difficult even though it should not be. say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it? echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal" If i run the above command, i get back all the... (4 Replies)
Discussion started by: SkySmart
4 Replies

9. UNIX for Dummies Questions & Answers

how to grep the word and display only the second word from it

hi, consider the below line in a text file, 'Y',getdate(),'N','V',NULL ..... 'N',getdate(),'Y','D',NULL ..... 'Y','N','Y',getdate(),'Y','D',NULL .... as u see above, i want only the second word after the getdate() word... getdate() will not come 2nd word alwys it may be any position but i... (11 Replies)
Discussion started by: prsam
11 Replies

10. UNIX for Dummies Questions & Answers

how to grep for a word and display only the word

Hi, When we "grep" for a word in a file, it returns the lines containing the word that we searched for. Is there a way to display only the words and not the entire line containing them. Thanks Ananth (6 Replies)
Discussion started by: ananthmm
6 Replies
Login or Register to Ask a Question