Navigation
  • Home
  • Recent
  • Most Active
  • Popular
  • Blog
  • Credits
  • RSS
  •   Interaction
  • Register
  • Statistics
  •   Help
  • Suggestions
  • Contact Us
  • How to Edit
  • Help



  • [Edit]



    grep is a command line utility originally written for use with the Unix operating system. The default behavior of grep takes a regular expression on the command line, reads standard input or a list of files, and outputs the lines containing matches for the regular expression.

    The name comes from a command in the Unix text editor ed that takes the form:

    g/re/p


    which means "search globally for lines matching the regular expression, and print them". There are various command line switches available when using grep that modify the default behavior.

    Other (incorrect) backronyms of the name exist, including: General Regular Expression Parser, General Regular Expression Print, Global Regular Expression Parser, and Global Regular Expression Print, though the last example is not entirely wrong.

    Common use:
    $ grep


        Grep
                Variations
                Usage as a conversational verb
            Examples
                egrep and fgrep
            See also

    top

    Variations
    There are many derivatives of grep, for example agrep which stands for approximate grep to facilitate fuzzy string searching, fgrep for fixed pattern searches, and egrep for searches involving more sophisticated regular expression syntax.
    fgrep and egrep are typically the same program as grep, which behaves differently depending on the name by which it is invoked. Tcgrep is a rewrite of grep which uses Perl regular expression syntax. All these variations of grep have been ported to many computer operating systems.

    Many other commands contain the word "grep." pgrep, for instance, displays the processes whose names match a regular expression.

    In Perl, grep is a built-in function, which when provided both a regular expression (or a general code block) and a list, it returns the elements of that list matched by the expression.

    The Microsoft Windows platform provides a utility called "findstr" which approximates much of the functionality of "grep."

    top

    Usage as a conversational verb
    As the name "grep" neatly fits the phonology of English, it is often used as a verb, meaning to search – usually, to search a known set of files, as one would with the grep utility. The direct object is the set of files searched: "Kibo grepped his Usenet spool for his name." Compare with google. Sometimes visual grep is used as a term meaning to look through text searching for something, in the manner of the grep program.

    In December 2003, the Oxford English Dictionary Online added draft entries for "grep" as both a noun and a verb.

    A common usage is the phrase "You can't grep dead trees" - meaning computerized documentation is better than printed documentation because computers can search documents by using tools such as grep.

    The word "grep" has also become a synonym for regular expressions themselves. Many text and word processors now employ regular expression search features, which those applications will often refer to as a "grep tool" or "grep mode" in which one creates "grep patterns", causing confusion, especially in non-Unix environments.

    top

    Examples
    To output all lines containing the string "foo" in the given list of files (here "
    grep foo

    To output all lines not containing the string "foo", use "-v":

    grep -v foo

    To output only the names of the matching files, use "-l":

    grep -l foo

    To output only the names of the Non-matching files, use "-L":
    grep -L foo

    To output all matching lines in the given list or files or directories, or recursively into their subdirectories ("." represents the current directory), use "-r":

    grep -r foo .


    The -r option may not be available on all Unix platforms.

    To match all lines beginning with once and ending with forever no matter how much whitespace the line ends with. Note that the ^ character specifies the starting point of a line just as $ denotes its end.

    grep ´^once.
      forever

    Grep also can read from standard input. Use ps -ef to list all running processes combined with grep $USER to output all lines with your username in them. (So you print out all the processes you are running.)

    ps -ef | grep $USER


    top

    egrep and fgrep
    `egrep' means `grep -E'. `fgrep' means `grep -F'.
      egrep = grep -E PATTERN. PATTERN is an extended regular expression
    Ex. You want to search for the words 'hello', 'goodbye' or both.
    With egrep you can do: egrep "hello|goodbye"
    searches for all lines containing 'hello', 'goodbye' or both.

      fgrep = -F, --fixed-strings PATTERN is a set of newline-separated strings
    Interpret PATTERN as a list of fixed strings, separated by new-
    lines, any of which is to be matched.

    top

    See also

     
    Search more:
     

       
    Source Privacy License Download Contact Us Atlas
    Scientus.org Dictionary (Yet Another Wiki) RC : 1.39
    This article is licensed under the GNU Free Documentation License [copyleft]. It uses material from the Wikipedia article "Grep". link