in reply to searching several files for a string at one time

Is there a general consensus on whether glob or grep is better for what I want to achieve? I can't seem to find how to make glob search multiple files for a string... for example, say I want to find files with the word 'monk' in them in my documents.. is it possible to do this? Thanks for the help
  • Comment on Re: searching several files for a string at one time

Replies are listed 'Best First'.
Re^2: searching several files for a string at one time
by Corion (Patriarch) on May 06, 2010 at 10:49 UTC

    glob and grep complement each other. glob is for finding filesystem entries (think "names"), and grep is for searching lists (like lines in a file). If you don't use the grep command line utility, then your Perl program will need to combine both. Use bsd_glob to find the files that are of interest, and then use grep to find the lines in those files.

      So the correct procedure would be to ask the user to specify the directory they wish to search in

      Use Glob to list all files in the directory? Or should I use glob to search for 'monk' and glob would bring back a list of files with 'monk' in them?

      then use Grep to specify which lines the word 'monk' is on?

      What is bsd_glob..

      Sorry for the completely noob like comments, but I'm a complete noob so it's to be expected.

        See File::Glob for bsd_glob. It is much like glob but has sane whitespace handling.

        You don't have to ask the user for the search term. See perlvar on @ARGV to see how you can retrieve the command line arguments that were given to your script.