Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of grep or egrep 1

Status
Not open for further replies.

MaheshRathi

Technical User
Jan 17, 2002
62
IN
Hi,

I am not able to use grep or egrep to get the matched lines for multiple patterns. For E.g. I want to get the lines matching to either "This is good" or "This is better" pattern.
The file can be like this ...

I say This is good or bad.
you say This is better may be.
Nobody knows how to get what is good or bad
then try it or do something

These are the content of file and want to get the lines 1,2 out of four.

Appreciate if you can provide me some pointers.
thanks,
Mahesh
 
Try this:
Code:
egrep 'This is (good|better)' /path/to/file

Hope This Help
PH.
 
...or this way

grep -E 'This is Good|This is better' /path/to/file

Both suggestions should work for you.

[afro2]
 
Hi,

Could someone help with the syntax here? I am trying to use four variables as a part of egrep

egrep "'$YDMON $YDAY'"|"'$TMON $TDAY'"

Thanks in advance

 
Replace this:
egrep "'$YDMON $YDAY'"|"'$TMON $TDAY'"
By this:
egrep "($YDMON $YDAY|$TMON $TDAY)"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top