Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a simple way to search for a sentence in windows directory on command prompt or can anyone suggest how to search for a sentence using perl?lets say i want to search for " connection failed" in c:\dropbox

  • Comment on Grep for a sentence in windows directory

Replies are listed 'Best First'.
Re: Grep for a sentence in windows directory
by Athanasius (Archbishop) on Oct 20, 2012 at 06:50 UTC

    Here is a one-liner you can use:

    >cd c:\dropbox >perl -Mautodie -E "local $/; @f = grep { if (-f) { open($fh, '<', $_) +; <$fh> =~ / connection failed/ && $_ } } glob('*'); say qq[@f];"

    (But I’m sure there are more elegant solutions.)

    Update: Using ack, as Anonymous Monk suggests, is as simple as:

    >cd c:\dropbox >ack -ln " connection failed"

    The -l switch causes filenames to be output instead of the matching lines, and the -n switch prevents recursion into subdirectories. See also http://betterthangrep.com/.

    Athanasius <°(((><contra mundum

Re: Grep for a sentence in windows directory
by Anonymous Monk on Oct 20, 2012 at 06:31 UTC