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 '
grep [OPTIONS] PATTERN [FILE...]
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 within single quotes (') or double quotes (") as per need. For example, use single quotes (') to avoid any bash expansion and double quotes (") for expansion.
A lot of
OPTIONS are available in
grep. Some of the important and widely used options...