Phil for Humanity

A Guide for the Survival of Humankind, and Improving the World, Society, and Yourself!


Popular Articles
  • Reasons For and Against
    Human Cloning
  • Globalization of the USA
  • The Pros and Cons of
    Capital Punishment
  • World's Stupidest Game

  • Latest Articles

  • Corporal Punishment
  • Garage Door Confusion
  • Childhood is Stressful
  • Chinese Saying about Children
  • Subscribe to RSS Feed

  • Main Menu

  • HOME
  • SAVE HUMANITY (50)
  • HELP THE WORLD (100)
  • IMPROVE GOVERNMENTS (90)
  • PERSONAL DEVELOPMENT (248)
  • COMPUTER HELP (126)
  • ARCHIVE (all articles)
  • SEARCH THIS SITE
  • CONTACT US
  • DISCLAIMER
  • PLEASE HELP: DONATE

  • UNIX Support: Recursively GREP


    I've always had two major problems with the UNIX "grep" command. First, the "grep" command will gladly read a non-text file, and thus produce garbage if the grep pattern was found. Second, the "grep" command can be used to search in all the files in a single directory, but the command will not recursively search all sub-directories. As a result, I wrote a Perl script, called recursive grep or "regrep.pl", to resolve these issues.

    Here is the syntax to run this script.

    $ regrep.pl <WORD> [PATH1] [PATH2] ... [OPTIONS]

    The first argument is the only required argument for the value to search or grep for. The optional "PATH" arguments that can be next are the directories where to start to recursively search for text files to grep. The default path is the current directory. Finally, the last optional argument is for these options:

    "-verbose" displays the matched lines for each file searched.
    "-list" lists the files that have matching text.
    "-edit" opens the matching files in an editor.
    "-nocase" performs a case insensitive search.

    Alternatively, you can just use the "-help" argument to see the usage and some examples of how to use this script.

    You can download this Perl script here, or you can copy-n-paste from down below. I would like to thank Monty Scroggins for enhancing this script with more options and teaching me a bit more Perl.



    by Phil B.

    Related Articles
     » Generate Random Numbers
     » ClearCase Support: How to Find Checked Out Elements
     » ClearCase Support: Common ClearCase Labeling Error Message







    Copyright © 2006-2010, Phil for Humanity. All Rights Reserved.