home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.os.linux.ubuntu      I preferred Xubuntu, seemed a bit faster      134,474 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 134,246 of 134,474   
   Jonathan N. Little to Adam   
   Re: how to grep for pattern1 AND pattern   
   14 Mar 25 09:30:15   
   
   From: lws4art@gmail.com   
      
   Adam wrote:   
   > On 03/13/2025 12:16 PM, Paul wrote:   
   >> On Thu, 3/13/2025 2:17 PM, Adam wrote:   
   >>>   
   >>> The following ...   
   >>>   
   >>> grep -e pattern1 -e pattern2 wget_output_file.txt   
   >>>   
   >>> is NOT giving the result that I'm looking for, which is BOTH patterns   
   >>> must be in the file.   
   >>   
   >> "The egrep variant supports an extended regular expression syntax   
   >> added by Alfred Aho   
   >>   after Ken Thompson's original regular expression implementation.[12]   
   >>   
   >>   The "fgrep" variant searches for any of a list of fixed strings using   
   >>   the Aho–Corasick string matching algorithm."   
   >>   
   >> *******   
   >>   
   >> sample.txt   
   >> ----------   
   >> I am a cat   
   >> I am a dog   
   >> I am a cat or a dog   
   >> I am an elephant   
   >>   
   >> (stdout)   
   >>   
   >> $ egrep "cat|dog" sample.txt   
   >> I am a cat   
   >> I am a dog   
   >> I am a cat or a dog   
   >>   
   >> "If at first you don't grep, try try again... with a egrep or a fgrep"   
   >> :-)   
   >>   
   >> It's a good thing these are documented.   
   >>   
   >>      Paul   
   >>   
   >   
   > I'm looking for AND (not OR) operator. So, both patterns must be in the   
   > file (not line) or FALSE is returned.   
   >   
      
   In this instance I just use cat:   
      
   (stdout)   
   $ cat sample.txt | grep cat | grep dog   
   I am a cat or a dog   
      
   BTW note on egrep deprecation:   
      
      
      
      
   --   
   Take care,   
      
   Jonathan   
   -------------------   
   LITTLE WORKS STUDIO   
   http://www.LittleWorksStudio.com   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca