Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
Global regular expression and print (GREP) is a command line text search utility used in Unix. The "grep" command searches files or standard input for lines that match a given regular expression. It then prints the matching lines to the program’s standard output.
The grep command allows a user to search one or more files for lines that contain a pattern.
A general example of the grep command format is "grep sat check.txt". This command prints all lines containing the text string "sat", regardless of word boundaries, from the file check.txt. For instance, if there are lines that contain text strings such as "fisat", "sat", "saturn", etc., all would be printed at the output terminal.
There are a variety of options used along with grep to display the output based on the requirement. A few of these options are:
Variations of grep are available for many operating systems. Early variations of grep included the "egrep" and "fgrep" commands. Egrep searches a file for a pattern using regular expression syntax, fgrep searches for a fixed character string. These variants of grep are included in most modern grep implementations as command-line switches. Other commands contain the word "grep" to indicate that they are search utilities. The "pgrep" utility, for example, displays a list of process names that match a specified regular expression.