![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to grep for a word and display only the word | ananthmm | UNIX for Dummies Questions & Answers | 6 | 05-29-2008 05:00 AM |
| grep for word | eltinator | Shell Programming and Scripting | 5 | 04-22-2008 05:07 PM |
| Grep for Particular Word | reddi22 | Shell Programming and Scripting | 2 | 01-22-2008 08:36 AM |
| grep a word from a line | Orbix | UNIX for Dummies Questions & Answers | 2 | 12-23-2007 08:52 AM |
| Grep for X character on a word | jjoves | UNIX for Dummies Questions & Answers | 5 | 08-06-2004 02:14 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Try this
cat <file> | grep -i -E "xls|jpg|bmp|doc|etc"
|
|
#3
|
||||
|
||||
|
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.
__________________
My brain is your brain |
|
#4
|
|||
|
|||
|
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
|
||||
|
||||
|
Champ, this is a forum you can add commentary.
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
__________________
My brain is your brain |
|
#6
|
||||
|
||||
|
On SunOS, /usr/xpg4/bin/grep is a modern grep that supports -E.
|
||||
| Google The UNIX and Linux Forums |