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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep command usage

Status
Not open for further replies.

pmcmicha

Technical User
May 25, 2000
353
I am using the korn shell in my unix system. I am attempting to grep more than 1 file at a time that have different names.&nbsp;&nbsp;I already tried to man grep, but it didn't produce any results that I could see would help.&nbsp;&nbsp;Here is an example of what I am trying to do...<br><br>Ex.&nbsp;&nbsp;cat file.log¦grep i9874 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cat file.log¦grep i9923<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cat file.log¦grep un3249<br><br>How can I make this one long command or can I?&nbsp;&nbsp;Thanks
 
Try <br>grep i9874 file.log;grep i9923 file.log;grep un3249 file.log<br><br>I would use awk for this <br>awk '/i9874¦i9923¦un3249/' file.log<br><br>
 
Thanks alot for the commands.&nbsp;&nbsp;The first one worked out great, but the second one wasn't as successful.&nbsp;&nbsp;Thanks again.
 
my way:<br>put pattern to the file (&quot;zzz&quot; for example)<br>and use command like grep -f zzz file.log
 
You need an <b>OR</b> or an <b>AND</b> operation?<br><br>The <b>OR<b> operation is:<br><br><FONT FACE=monospace><br><b>egrep</b> &quot;text1<b>¦</b>text2<b>¦</b>text3&quot; files<br></font><br>That will show you the lines with text1 OR with text2 OR with text3. If you don't have access to egrep try using <b>grep -E</b> &quot;text1¦text2¦text3&quot; files<br><br>The and operation is<br><br><FONT FACE=monospace><br>grep &quot;text1&quot; files ¦ grep &quot;text2&quot; ¦ grep &quot;text3&quot;<br></font><br>That will show you the lines with text1 AND with with text3.<br><br>I hope it works...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top