Global-Regular-Expression-Print

Why Trust Techopedia

What Does Global-Regular-Expression-Print Mean?

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.

Advertisements

Techopedia Explains Global-Regular-Expression-Print

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:

  • “-i” – Ignore case sensitivity
  • “-b” – Display block number at beginning of every line
  • “-l” – Display file names but not matched lines
  • “-n” – Display matched lines and line numbers
  • “-v” – Display lines that do not match

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.

Advertisements

Related Terms

Margaret Rouse
Senior Editor
Margaret Rouse
Senior Editor

Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.