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!

how to search two patterns using grep???

Status
Not open for further replies.

AQWQ

Programmer
Aug 5, 2001
33
IN
i wanna search two patterns simultaneosly using grep.I have tried using grep -f <filename which has patterns entry>.But i don need this..i wanna avoid this look up in to the fileis there any way??
Also i need to know whether there is any function to compare two strings in unix???i tried ueing if test <string1> -eq <string2> but its not working...


Thanx in advance Santhosh Ravindran
 
Hi,

to search two patterns use :

grep -E &quot;pattern1|pattern2&quot; file, the pipe is like an &quot;OR condition&quot;.

To test string use &quot; &quot; :
&quot;$STRING&quot; -eq &quot;$STRING2&quot;

You should go in the man of KSH to get more information, all tests are explained.

Regards.

Fcail
 
Hi fcail ur suggestion for grep worked out.but test failed.i referred man section and found out that we can use = symbol to compare two strings.

ie., test $string1 = $string2 returns true if string are same.

Thanx Santhosh Ravindran
 
Santosh,

Depends upon which shell you are using, fcail's suggestion looks ok for sh and ksh scripts. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top