grep

Grep [ gɹɛp ] is a program that is defined under the operating systems Unix and Unix- derivatives of the search and filtering strings from files. It was originally developed by Ken Thompson.

The term grep stands for global / regular expression / print or globally search for a regular expression and print out matched lines, eg " global search for a regular expression and output matching lines". Historically, the name evolved from the command g / re / p of the standard Unix editor ed

There are numerous variants such as egrep, fgrep and agrep that allow a fuzzy search for text strings.

Application

In the command line grep is used mostly for searching files. The call has the basic form:

Grep [options ] search string [File ( list) ] The command can also be used in shell scripts, for example in pipes used.

Through command line switch, the operation of grep can be changed, so it is possible, for example,

  • Pick out all lines that do not contain the specified text,
  • Only pick out rows where the search pattern is included as a whole word,
  • The line numbers in which the text is to be output, and
  • Output the file names of all files that contain the specified text.

The GNU version also offers the opportunity to not spend the entire row in which an expression occurs, but only all occurrences of the expression itself

Areas of application

Grep is then primarily used when files must be searched, for example, the source files of a computer program or logs. In collaboration with find can an entire tree to be read.

$ Find / home / user -exec grep- H " password " {} \; This command searches all files in the source directory of the user's username after the password string and displays the matching lines along with the file name, the display of the file name is triggered by the -H option.

Some grep versions allow a shorter formulation using the -r option:

$ Grep -r " password " / home / username A second area of ​​application is the use as a line filter in a chain of commands, such as:

$ Tail -1000 / var / log / mail | grep " mail address" agrep

Agrep (Approximate GREP ) is a program that is not from the family of UNIX grep programs. In contrast to the UNIX grep family of programs enables a fuzzy ( fuzzy) text string search.

Agrep was developed during the years 1988-1991 by Udi Manber and Sun Wu at the University of Arizona and is the core of the search engine GLIMPSE and HARVEST. The program used for a variety of built-in search algorithms one who is best suited to the regular expression the user input ( search string) and the fastest search possible.

By 1996, it was first, and later ported to OS / 2 and DOS to Windows.

Agrep is free for any kind of use, but may not be distributed for the purpose of obtaining profit. This is the license of agrep in conflict with paragraph 1 of the Open Source Definition.

Tre- agrep

With Tre- agrep is a reimplementation of agrep available, which is under the liberal BSD license.

Egrep

Egrep (extended grep ) is suitable for easy searching with extended regular expressions.? Thus the sign, , { ,}, have |, (, and ) for egrep a special meaning for the term, and must end with a backslash: be (English backslash) protected if they are to be found as text.

Fgrep

Fgrep can always be used instead of grep, if the pattern to be searched does not contain regular expressions. All special characters in the pattern string of characters lose their special meaning and are understood as being part of the pattern. Fgrep operates by slightly faster than grep and is especially useful when searching large amounts of data. One uses the Aho Corasick this algorithm, which also served as the original version.

Microsoft Windows

How many programs, there are also ports of grep on the Windows platform. As a built-in command Windows knows the commands find and findstr, which provide a function similar to grep. In the Resource Kit Tools QGREP.EXE is included.

Comments

35012
de