AskDefine | Define grep

User Contributed Dictionary



From an idiomatic command sequence in the qed and ed text editors: ‘g/re/p’, meaning: globally search for a regular expression and print.


  1. A program which selects lines in a file which match a given pattern.


  1. To use the program grep to search in a file.
  2. By extension, to search anything (perhaps a paper document by eye).

Derived terms


use the program grep
  • Dutch: greppen
search anything
  • Dutch: greppen, zoeken

External links






  1. A grasp.


  1. Past tense of gripe.



  1. A tool, resembling a pitchfork but where both handle and prongs are shorter and sturdier, and which is used more for digging than lifting


  1. Past tense of gripa

Extensive Definition

grep (Global Regular Expression Print) is a command line utility that was originally written for use with the Unix operating system. Given a list of files or standard input to read, grep searches for lines of text that match one or many regular expressions, and outputs only the matching lines.

Function and usage

The program's name derives from the command used to perform a similar operation, using the Unix text editor ed:
This command searches a file globally for lines matching a given regular expression, and prints them.
There are various command line switches available when using grep that modify this default behavior including printing lines which do not match, finding or excluding files to search, and annotating the output in various ways. There are also multiple modern implementations of the classic Unix grep, each with a unique feature set.
This is an example of a common grep usage:
grep apple fruitlist.txt
Grep would return, in this case, all of the lines in file fruitlist.txt with at least one instance of 'apple' in them. Keep in mind that grep would not return lines with 'Apple' (capital A) because by default grep is case sensitive. Like most Unix commands grep accepts flags which can be used to change this and many other behaviors. For example:
grep -i apple fruitlist.txt
This would return all lines with the words 'apple', 'Apple', 'apPLE', or any other mixing of capital and lower case.
The option -e can also be used to declare multiple patterns for searching on the command line with some versions of grep.


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, returns the elements of that list matched by the expression. 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.
Grep options included in flavours of Unix may be different:
  • Linux, include -B (before) -A (after)
  • AIX, include -p (paragraph)

Usage as a conversational verb

As the name "grep" neatly fits the phonotactics 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 (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.

egrep and fgrep

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 simply reads a set of fixed strings to search for from a file. These early variants are embodied in most modern grep implementations as simple command-line switches (e.g. -E and -F respectively in GNU grep).


  • Grep: Searching for a Pattern
  • Hume, Andrew 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

grep in Bulgarian: Grep
grep in Czech: Grep
grep in Danish: Grep
grep in German: Grep
grep in Modern Greek (1453-): Grep
grep in Spanish: Grep
grep in French: Grep
grep in Italian: Grep
grep in Hungarian: Grep
grep in Dutch: Grep
grep in Japanese: Grep
grep in Norwegian: Grep
grep in Polish: Grep
grep in Portuguese: Grep
grep in Russian: Grep
grep in Slovenian: grep
grep in Finnish: Grep
grep in Chinese: Grep
Privacy Policy, About Us, Terms and Conditions, Contact Us
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2
Material from Wikipedia, Wiktionary, Dict
Valid HTML 4.01 Strict, Valid CSS Level 2.1