<div dir="ltr"><div><div>grep -l alpha * | xargs grep -l beta | xargs grep -l charlie | xargs grep -l delta<br><br>Does that do it?<br><br></div><div>"-l" prints the filenames rather than the matching lines, which then becomes the input for xargs in the next line.<br></div><div><br></div></div><div>You'd have to expand the regexes slightly if the surrounding whitespace was important to you.<br></div><div><div><div><br>On Mon, Nov 23, 2015 at 4:02 PM, Martin <span dir="ltr"><<a href="mailto:martin@ml1.co.uk" target="_blank">martin@ml1.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Just need the file names for files that have those four words.<br>
<br>
There should be a surrounding 'white space' or end/start of line.<br>
<br>
And the words can appear in any order in the file...<br>
<br>
<br>
The words may well be on two adjacent lines, hence why the chain of<br>
greps isn't the full answer...<br>
<br>
?<br>
<br>
Cheers,<br>
Martin<br>
<span><br>
<br>
<br>
Richard Parsons wrote:<br>
> The four words have to be next to each other separated by spaces?<br>
><br>
> Do you want the grep to flag the matching file, or is the specific line<br>
> important?<br>
><br>
> On Mon, Nov 23, 2015 at 3:33 PM, Martin <<a href="mailto:martin@ml1.co.uk" target="_blank">martin@ml1.co.uk</a><br>
</span><span>> <mailto:<a href="mailto:martin@ml1.co.uk" target="_blank">martin@ml1.co.uk</a>>> wrote:<br>
><br>
>     Folks,<br>
><br>
>     One of those clever one-liners please?<br>
><br>
><br>
>     How to grep for four words in a file that can appear in any permutation?<br>
><br>
>     ?<br>
><br>
>     Cheers,<br>
>     Martin<br>
><br>
><br>
>     --<br>
>     - ╔═══════════════════╦══════════════════════════════════════════╗<br>
>     - ║   Martin Lomas    ║ OpenPGP (GPG/PGP) Public Key: 0xCEE1D3B7 ║<br>
>     - ║ martin@ ml1 co uk ║ Import from   hkp://<a href="http://subkeys.pgp.net" rel="noreferrer" target="_blank">subkeys.pgp.net</a><br>
</span>>     <<a href="http://subkeys.pgp.net" rel="noreferrer" target="_blank">http://subkeys.pgp.net</a>>   or ║<br>
<span>>     - ║ ----------------- ║ http:// ml1 .co .uk/martin_ml1_co_uk.gpg ║<br>
>     - ╚═══════════════════╩══════════════════════════════════════════╝<br>
><br>
>     _______________________________________________<br>
>     Nottingham mailing list<br>
</span>>     <a href="mailto:Nottingham@mailman.lug.org.uk" target="_blank">Nottingham@mailman.lug.org.uk</a> <mailto:<a href="mailto:Nottingham@mailman.lug.org.uk" target="_blank">Nottingham@mailman.lug.org.uk</a>><br>
<span>>     <a href="https://mailman.lug.org.uk/mailman/listinfo/nottingham" rel="noreferrer" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/nottingham</a><br>
><br>
><br>
><br>
><br>
> --<br>
> Redwood Legal<br>
</span>> <a href="mailto:rp@redwoodlegal.co.uk" target="_blank">rp@redwoodlegal.co.uk</a> <mailto:<a href="mailto:rp@redwoodlegal.co.uk" target="_blank">rp@redwoodlegal.co.uk</a>><br>
<span>> Office: 02030 956010<br>
> Mobile: 07544 822706<br>
> 138-140 Southwark Street, London, SE1 0SW<br>
><br>
> This firm is authorised and regulated by the Solicitors Regulation<br>
> Authority (SRA ID 427552)<br>
><br>
><br>
</span><div><div>> _______________________________________________<br>
> Nottingham mailing list<br>
> <a href="mailto:Nottingham@mailman.lug.org.uk" target="_blank">Nottingham@mailman.lug.org.uk</a><br>
> <a href="https://mailman.lug.org.uk/mailman/listinfo/nottingham" rel="noreferrer" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/nottingham</a><br>
<br>
<br>
--<br>
- ╔═══════════════════╦══════════════════════════════════════════╗<br>
- ║   Martin Lomas    ║ OpenPGP (GPG/PGP) Public Key: 0xCEE1D3B7 ║<br>
- ║ martin@ ml1 co uk ║ Import from   hkp://<a href="http://subkeys.pgp.net" rel="noreferrer" target="_blank">subkeys.pgp.net</a>   or ║<br>
- ║ ----------------- ║ http:// ml1 .co .uk/martin_ml1_co_uk.gpg ║<br>
- ╚═══════════════════╩══════════════════════════════════════════╝<br>
<br>
_______________________________________________<br>
Nottingham mailing list<br>
<a href="mailto:Nottingham@mailman.lug.org.uk" target="_blank">Nottingham@mailman.lug.org.uk</a><br>
<a href="https://mailman.lug.org.uk/mailman/listinfo/nottingham" rel="noreferrer" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/nottingham</a></div></div></blockquote></div><br><br clear="all"><br>-- <br><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="font-size:small"><font color="#000000">Redwood Legal</font></div><div style="font-size:small"><font color="#000000"><a href="mailto:rp@redwoodlegal.co.uk" target="_blank">rp@redwoodlegal.co.uk</a><br></font></div><div style="font-size:small"><font color="#000000">Office: 02030 956010</font></div><div style="font-size:small"><font color="#000000">Mobile: 07544 822706<br></font></div><div style="font-size:small"><font color="#000000">138-140 Southwark Street, London, SE1 0SW<br></font></div><div style="font-size:small"><font color="#000000"><br></font></div><div style="font-size:small"><font color="#000000">This firm is authorised and regulated by the Solicitors Regulation Authority (SRA ID 427552)</font><br></div></div></div></div></div></div></div>
</div></div></div></div></div>