The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to make menu of result from egrep tvrman Shell Programming and Scripting 5 08-21-2008 11:16 AM
egrep/grep result of more files tvrman Shell Programming and Scripting 3 08-07-2008 08:29 AM
Egrep cheat sheet anywhere? Looking for meaning of egrep -c leelm UNIX for Dummies Questions & Answers 2 01-11-2008 03:37 PM
Outputting formatted Result log file from old 30000 lines result log<help required> vikas.iet Shell Programming and Scripting 5 12-02-2007 10:43 PM
egrep counting every 2 lines of result as 1 Orbix UNIX for Dummies Questions & Answers 1 11-20-2007 08:12 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2008
tvrman tvrman is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
using egrep to get result

Hi all,

Can egrep using AND OR ?, like egrep -i "title.$1" AND "category.$2" ./home....

I want to give two search criteria, the files where egrep is seaching in for example
looks like below rows.
title this is an test
category space

(command line input)
$1 script.sh this space

thanks
  #2 (permalink)  
Old 08-31-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
With egrep:

search for $var1 OR $var2:

Code:
egrep "[$var1]|[$var2]" file
search for $var1 AND $var2:

Code:
egrep "$var1.*$var2|$var2.*$var1" file
Regards
  #3 (permalink)  
Old 08-31-2008
tvrman tvrman is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
Thank you, that's exact what i need.
  #4 (permalink)  
Old 08-31-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Actually the examples are wrong. But this is a duplicate of another thread; see http://www.unix.com/shell-programmin...-new-post.html
  #5 (permalink)  
Old 08-31-2008
tvrman tvrman is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
Hi Era,
thank you very much, this should be the solution? var1.*var2|var2.*var1, should this create the AND?
  #6 (permalink)  
Old 08-31-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Yes, that checks for var1 and var2 on one and the same line, in any order.
  #7 (permalink)  
Old 08-31-2008
tvrman tvrman is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
thanks Era, just what i was looking for.
Sponsored Links
Closed Thread

Bookmarks

Tags
egrep and, egrep or

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0