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,242 of 134,474    |
|    Paul to Adam    |
|    Re: how to grep for pattern1 AND pattern    |
|    13 Mar 25 16:44:49    |
      From: nospam@needed.invalid              On Thu, 3/13/2025 3:56 PM, 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.       >               sample.txt       ----------              I am a cat       I am a dog       I am a cat and a dog       I am a dog and a cat       I am an elephant              I had to use CoPilot, as my crafting experiments all failed.              $ egrep 'cat.*dog|dog.*cat' sample.txt # cat followed by dog       or dog followed by cat       I am a cat and a dog       I am a dog and a cat       $              Note that, this needs to be rigorously tested.       Just based on my failures before asking CoPilot,       you can't just assume this actually works...              I am a cat       I am a dog       I am a cat and a dog       I am a dog and a cat       I am a dog dog and a cat       I am a dog dog and a cat dog       I am a dog dog and a cat cat       I am a dog cat and a dog cat       I am a dog cat and a cat dog       I am an elephant              $ egrep 'cat.*dog|dog.*cat' sample.txt       I am a cat and a dog       I am a dog and a cat       I am a dog dog and a cat       I am a dog dog and a cat dog       I am a dog dog and a cat cat       I am a dog cat and a dog cat       I am a dog cat and a cat dog       $              I would imagine this technique rapidly runs out of legs.               Paul              --- 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