grep (Global Regular Expression Print) is a command line utility that was originally written for use with the Unix operating system. Unix (officially trademarked as UNIX, sometimes also written as Unix with Small caps) is a computer 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. In Unix and Unix-like operating systems as well as certain Programming language interfaces the standard streams are preconnected input and output channels In Computing, regular expressions provide a concise and flexible means for identifying strings of text of interest such as particular characters words or patterns of characters
Contents |
The program's name derives from the command used to perform a similar operation, using the UNIX text editor ed:
g/re/p
This command searches a file globally for lines matching a given regular expression, and prints them. ed is the standard Text editor on the Unix operating system ed was originally written by Ken Thompson and contains one of the first implementations of In Computing, regular expressions provide a concise and flexible means for identifying strings of text of interest such as particular characters words or patterns of characters
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. Text sometimes exhibits case sensitivity; that is words can differ in meaning based on differing use of uppercase and lowercase letters Like most Unix commands grep accepts flags which can be used to change this and many other behaviors. In computer Command line interfaces a command line argument is an argument sent to a program being called For example:
grep -i apple fruitlist. txt
This would return all lines with the words 'apple', 'Apple', 'apPLE', or any other mixing of upper 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. agrep (approximate Grep) is a Fuzzy string searching program developed by Udi Manber and Sun Wu between 1988 and 1991 for use with the Approximate string search is the name that is used for a category of techniques for finding strings that approximately match some given pattern string fgrep and egrep are typically the same program as grep, which behaves differently depending on the name by which it is invoked. Tcgrep[1] is a rewrite of grep which uses Perl regular expression syntax. In Computing, regular expressions provide a concise and flexible means for identifying strings of text of interest such as particular characters words or patterns of characters 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. pgrep is a command line utility initially written for use with the Solaris 7 operating system
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. NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below In Computing, regular expressions provide a concise and flexible means for identifying strings of text of interest such as particular characters words or patterns of characters In functional programming languages, this higher-order function is typically named "filter" instead. In Computer science, functional programming is a Programming paradigm that treats Computation as the evaluation of mathematical functions and In Mathematics and Computer science, higher-order functions or '''functionals''' are functions which do at least one of the following
The DOS, OS/2 and Microsoft Windows platforms provide the find command for simple string searches. DOS, short for "Disk Operating System" is a shorthand term for several closely related Operating systems that dominated the IBM PC compatible market OS/2 is a computer Operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively Microsoft Windows is a series of Software Operating systems and Graphical user interfaces produced by Microsoft. In Computing, find is a command in the Command line interpreters ( shells) of DOS, OS/2 and Microsoft Windows Windows also provides the "findstr" command which approximates much of the functionality of "grep", or you can use the cygwin grep ported version. Cygwin (ˈsɪɡwɪn is a collection of tools originally developed by Cygnus Solutions to provide in Microsoft Windows a command line and programming interface familiar
Grep options included in flavours of Unix may be different:
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. Phonotactics (in Greek phone = voice and tactic = course is a branch of Phonology that deals with restrictions in a Language on the English is a West Germanic language originating in England and is the First language for most people in the United Kingdom, the United States The direct object is the set of files searched: "Kibo grepped his Usenet spool for his name. Kibo (ˈkaɪboʊ is the Nickname and Username of James Parry (born July 13 1967) a Usenetter known for his Sense Usenet, a Portmanteau of "user" and "network" is a world-wide distributed Internet discussion system " Compare with google. The Verb to google (also spelled to Google) refers to using the Google search engine to obtain information on the Web. 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. The Oxford English Dictionary ( OED) published by the Oxford University Press (OUP is a comprehensive Dictionary of the English
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. Paper is thin material mainly used for writing upon printing upon or packaging
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.
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. Kenneth Lane Thompson (born February 4 1943) commonly referred to as Ken Thompson (or simply 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). The GNU Project is a Free software, Mass collaboration project announced in 1983 by Richard Stallman.