Filtering an output using grep

One of the powerful and widely used command in shell is grep. It searches in an input file and matches lines in which the given pattern is found. By default, all the matched patterns are printed on stdout that is usually terminal. We can also redirect the matched output to other streams such as file. Instead of giving an input from a file, grep can also take the input from the redirected output of the command executed on the left-hand side of '|'.

Syntax

The syntax of using the grep command is as follows:

grep [OPTIONS] PATTERN [FILE...]

Here, FILE can be multiple files for a search. If no file is given as an input for a search, it will search the standard input.

PATTERN can be any valid regular expression. Put PATTERN ...

Get Linux Shell Scripting Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.