The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
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

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-17-2002
Registered User
 

Join Date: Aug 2002
Posts: 3
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  
Old 10-17-2002
Registered User
 

Join Date: Jun 2002
Location: Amsterdam (Netherlands)
Posts: 142
Try this

cat <file> | grep -i -E "xls|jpg|bmp|doc|etc"
  #3  
Old 10-17-2002
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
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  
Old 10-17-2002
Registered User
 

Join Date: Jun 2002
Posts: 64
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
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
Champ, this is a forum you can add commentary. 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


__________________
My brain is your brain
  #6  
Old 10-18-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,609
On SunOS, /usr/xpg4/bin/grep is a modern grep that supports -E.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0