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,245 of 134,474    |
|    rbowman to Adam    |
|    Re: how to grep for pattern1 AND pattern    |
|    14 Mar 25 02:58:58    |
      From: bowman@montana.com              On Thu, 13 Mar 2025 14:38:45 -0700, Adam wrote:              > 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-to-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.       > ========================================================================              As a variation on that theme:              find . -name "*.c" | xargs grep foobar              Not what you asked for but handy.              --- 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