This section focuses on basic grep. Most of the flags for basic grep apply equally to the other versions, which we’ll discuss later.
Basic grep, or grep -G, is
the default pattern matching type that is used when calling
grep. grep interprets the given
set of patterns as a basic regular expression when it executes the
command. This is the default grep program that is
called, so the
option is almost always redundant.
Like any command, grep comes with a handful of options that control both the matches found and the way grep displays the results. The GNU version of grep offers most of the options listed in the following subsections.
grep -e -style doc.txt
Ensures that grep recognizes the pattern as the regular expression argument. Useful if the regular expression begins with a hyphen, which makes it look like an option. In this case, grep will look for lines that match “-style”.
grep -f pattern.txt searchhere.txt
Takes patterns from
option allows you to input all the patterns you want to match into
a file, called pattern.txt here. Then,
grep searches for all the patterns from
pattern.txt in the designated
file searchhere.txt. The
patterns are additive; that is, grep returns
every line that matches any pattern. The pattern file must list
one pattern per line. If pattern.txt is empty, nothing will
grep -i 'help' me.txt
Ignores capitalization in the given ...