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,243 of 134,474   
   Adam to Lem Novantotto   
   Re: how to grep for pattern1 AND pattern   
   13 Mar 25 14:38:45   
   
   From: adam@no_thanks.com   
      
   On 03/13/2025 01:44 PM, Lem Novantotto wrote:   
   > Il Thu, 13 Mar 2025 12:56:42 -0700, Adam ha scritto:   
   >   
   >> I'm looking for AND (not OR) operator. So, both patterns must be in the   
   >> file (not line) or FALSE is returned.   
   >   
   > $ ( grep -l pattern1 file | xargs grep -l pattern2 ) || false   
   >   
   > You can do it better. Read the manual of the involved commands, if you   
   > like.   
   >   
      
   Thanks, your post led me to...   
      
   How can I search a file to see if it contains multiple patterns anywhere   
   in the file?   
   https://askubuntu.com/questions/1501703/how-can-i-search-a-file-   
   o-see-if-it-contains-multiple-patterns-anywhere-in-the   
   ========================================================================   
   waltinator's answer...   
      
   It can be done using multiple grep commands. Read man grep xargs, and do   
   something like   
      
   grep -l 'pattern1' -f filelist | \   
        xargs grep -l 'pattern2` | \   
        xargs grep -l 'pattern3'   
      
   The first grep produces a list of files containing the first pattern.   
   The second (xargs grep) searches for the second pattern in the files   
   containing the first pattern.   
   ========================================================================   
      
   --- 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