Grep

Grep

grep is a command line text search utility originally written for Unix. The program's name derives from the Unix ed command, "g/re/p" which performs a similar operation.cite web|url=http://www.catb.org/~esr/jargon/html/G/grep.html |title=grep |accessdate=2006-06-29 |author=Raymond, Eric (editor) |last=Raymond |first=Eric |authorlink=Eric S. Raymond |work=Jargon File ]

Although "grep" is not strictly an acronym, the letters are taken from "global" / "regular expression" / "print", a series of instructions for the ed text editor. The "grep" command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.

Usage

This is an example of a common grep usage:

grep apple fruitlist.txt

In this case, grep prints all lines containing 'apple' from the file "fruitlist.txt", regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The grep command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.

Like most Unix commands, grep accepts command line arguments to change this and many other behaviors. For example:

grep -i apple fruitlist.txt

This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells grep to be "case insensitive", or to "ignore case".

To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):

grep -w apple fruitlist.txt

For simplicity, these examples match a single English word, but regular expressions can be extremely sophisticated (and notoriously difficult to decipher, or write-only).

For further details on grep command line arguments and regular expression capabilities/syntax, refer to the particular implementation's documentation.

Variations

There are countless implementations and derivatives of grep available for many operating systems. Early variants of grep included egrep and fgrep. The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern grep implementations as command-line switches (e.g. -E and -F respectively in GNU grep). In such combined implementations, grep may also behave differently depending on the name by which it is invoked, allowing fgrep, egrep, and grep to be links to the same program.

Tcgrep is an implementation of grep that uses Perl regular expression syntax.

Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The pgrep utility, for instance, displays the processes whose names match a given regular expression.

In Perl, grep is a built-in function that finds elements in a list. In functional programming languages, this higher-order function is typically named "filter" instead.

The DOS, OS/2 and Microsoft Windows platforms provide the find command for simple string searches. Windows also provides the "findstr" command which approximates much of the functionality of "grep", or you can use the cygwin grep ported version.

Usage as a conversational verb

The term "grep" can be 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". Sometimeswhen "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 (paper is made from dead trees) 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.

ee also

* Boyer – Moore string search algorithm
* List of Unix utilities

References

*
*Hume, Andrew " [http://www3.interscience.wiley.com/cgi-bin/abstract/113446956/ABSTRACT?CRETRY=1&SRETRY=0 A tale of two greps] ," Software—Practice and Experience 18, ( 11 ), 1063–1072 ( 1988).
* Hume, Andrew "Grep wars: The strategic search initiative." In Peter Collinson, editor, "Proceedings of the EUUG Spring 88 Conference", pages 237–245, Buntingford, UK, 1988. European UNIX User Group.

External links

*
* [http://www.linfo.org/grep.html The grep Command] - by The Linux Information Project (LINFO)
* [http://ridiculousfish.com/blog/archives/2006/05/30/old-age-and-treachery/ "The Treacherous Optimization"] - article on tradeoffs in grep to favor best-case over worst-case scenarios
* [http://stts.se/index.php?lang_id=en_uk&page=egrep Egrep for linguists] An introduction to egrep
* [http://tony.abou-assaleh.net/GREPs Tony Abou-Assaleh's list of Greps]
* [http://www.gnu.org/software/grep/doc/grep_13.html#SEC13 Usage of grep Command]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Grep — est un programme en ligne de commande initialement écrit pour Unix utilisant l algorithme d Aho Corasick. Le comportement habituel de grep est de recevoir une expression rationnelle en ligne de commande, de lire les données sur l entrée standard… …   Wikipédia en Français

  • grep — est un programme en ligne de commande de recherche de chaînes de caractères, initialement écrit pour UNIX par Ken Thompson, puis amélioré par l utilisation de l algorithme d Aho Corasick. Il existe de nombreuses implémentations grep sur… …   Wikipédia en Français

  • Grep — Saltar a navegación, búsqueda grep es una utilidad de la línea de comandos escrita originalmente para ser usada con el sistema operativo Unix. Usualmente, grep toma una expresión regular de la línea de comandos, lee la entrada estándar o una… …   Wikipedia Español

  • grep — es una utilidad de la línea de comandos escrita originalmente para ser usada con el sistema operativo Unix. Usualmente, grep toma una expresión regular de la línea de comandos, lee la entrada estándar o una lista de archivos, e imprime las líneas …   Wikipedia Español

  • Grep — grep  утилита командной строки, которая находит на вводе строки, отвечающие заданному регулярному выражению, и по умолчанию выводит их. Название представляет собой акроним английской фразы «search globally for lines matching the regular… …   Википедия

  • GREP — [gɹɛp] ist ein wichtiges Programm, das unter den Betriebssystemen Unix und Unix Derivaten der Suche und Filterung definierter Zeichenketten in Dateien dient. Es wurde ursprünglich von Ken Thompson entwickelt.[1] Der Begriff steht für… …   Deutsch Wikipedia

  • Grep — [gɹɛp] ist ein wichtiges Programm, das unter den Betriebssystemen Unix und Unix Derivaten der Suche und Filterung definierter Zeichenketten in Dateien dient. Es wurde ursprünglich von Ken Thompson entwickelt.[1] Der Begriff steht für… …   Deutsch Wikipedia

  • grep — [gɹɛp] ist ein Programm, das unter den Betriebssystemen Unix und Unix Derivaten der Suche und Filterung definierter Zeichenketten aus Dateien dient. Es wurde ursprünglich von Ken Thompson entwickelt.[1] Der Begriff grep steht für global/regular… …   Deutsch Wikipedia

  • grep —   [Abk. für Global Regular Expression, dt. »allgemeiner regulärer Ausdruck«], ein Systemprogramm in Unix, mit dem nach bestimmten Zeichenmustern in Dateien gesucht werden kann. Solche Zeichenmuster können einfache Zeichenketten sein, komplexe… …   Universal-Lexikon

  • grep — GREP, grepuri, s.n. Grepfrut. – Prescurtare din grepfrut. Trimis de gall, 13.09.2007. Sursa: DEX 98  GREP s. v. grepfrut. Trimis de siveco, 13.09.2007. Sursa: Sinonime  grep s. n., pl. grépuri Trimis de siveco, 10.08.2004. Sursa: Dicţionar …   Dicționar Român

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”