[Nottingham] Help... How to grep four words in a file appearing in any permutation?

Richard Parsons rp at redwoodlegal.co.uk
Mon Nov 23 16:09:49 UTC 2015


grep -l alpha * | xargs grep -l beta | xargs grep -l charlie | xargs grep
-l delta

Does that do it?

"-l" prints the filenames rather than the matching lines, which then
becomes the input for xargs in the next line.

You'd have to expand the regexes slightly if the surrounding whitespace was
important to you.

On Mon, Nov 23, 2015 at 4:02 PM, Martin <martin at ml1.co.uk> wrote:

> Just need the file names for files that have those four words.
>
> There should be a surrounding 'white space' or end/start of line.
>
> And the words can appear in any order in the file...
>
>
> The words may well be on two adjacent lines, hence why the chain of
> greps isn't the full answer...
>
> ?
>
> Cheers,
> Martin
>
>
>
> Richard Parsons wrote:
> > The four words have to be next to each other separated by spaces?
> >
> > Do you want the grep to flag the matching file, or is the specific line
> > important?
> >
> > On Mon, Nov 23, 2015 at 3:33 PM, Martin <martin at ml1.co.uk
> > <mailto:martin at ml1.co.uk>> wrote:
> >
> >     Folks,
> >
> >     One of those clever one-liners please?
> >
> >
> >     How to grep for four words in a file that can appear in any
> permutation?
> >
> >     ?
> >
> >     Cheers,
> >     Martin
> >
> >
> >     --
> >     - ╔═══════════════════╦══════════════════════════════════════════╗
> >     - ║   Martin Lomas    ║ OpenPGP (GPG/PGP) Public Key: 0xCEE1D3B7 ║
> >     - ║ martin@ ml1 co uk ║ Import from   hkp://subkeys.pgp.net
> >     <http://subkeys.pgp.net>   or ║
> >     - ║ ----------------- ║ http:// ml1 .co .uk/martin_ml1_co_uk.gpg ║
> >     - ╚═══════════════════╩══════════════════════════════════════════╝
> >
> >     _______________________________________________
> >     Nottingham mailing list
> >     Nottingham at mailman.lug.org.uk <mailto:Nottingham at mailman.lug.org.uk>
> >     https://mailman.lug.org.uk/mailman/listinfo/nottingham
> >
> >
> >
> >
> > --
> > Redwood Legal
> > rp at redwoodlegal.co.uk <mailto:rp at redwoodlegal.co.uk>
> > Office: 02030 956010
> > Mobile: 07544 822706
> > 138-140 Southwark Street, London, SE1 0SW
> >
> > This firm is authorised and regulated by the Solicitors Regulation
> > Authority (SRA ID 427552)
> >
> >
> > _______________________________________________
> > Nottingham mailing list
> > Nottingham at mailman.lug.org.uk
> > https://mailman.lug.org.uk/mailman/listinfo/nottingham
>
>
> --
> - ╔═══════════════════╦══════════════════════════════════════════╗
> - ║   Martin Lomas    ║ OpenPGP (GPG/PGP) Public Key: 0xCEE1D3B7 ║
> - ║ martin@ ml1 co uk ║ Import from   hkp://subkeys.pgp.net   or ║
> - ║ ----------------- ║ http:// ml1 .co .uk/martin_ml1_co_uk.gpg ║
> - ╚═══════════════════╩══════════════════════════════════════════╝
>
> _______________________________________________
> Nottingham mailing list
> Nottingham at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/nottingham
>



-- 
Redwood Legal
rp at redwoodlegal.co.uk
Office: 02030 956010
Mobile: 07544 822706
138-140 Southwark Street, London, SE1 0SW

This firm is authorised and regulated by the Solicitors Regulation
Authority (SRA ID 427552)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/nottingham/attachments/20151123/0f9ac4c1/attachment-0001.html>


More information about the Nottingham mailing list