Using grep

If we wanted to talk properly about grep, an entire book would not be enough. grep supports many engines along with BRE and ERE. It supports engines such as Perl-compatible regular expression (PCRE).

The grep is a very powerful tool that most system administrators use every day. We just want to enlighten the point of using BRE and ERE patterns as we did with sed and AWK.

grep tool understands BRE patterns by default, and if you want to use ERE patterns, you should use the -E option.

Let's work with the following example file and use a BRE pattern:

Welcome to shell scripting.love shell scripting.shell scripting is awesome.

Let's test a BRE pattern:

$ grep '.sh' myfile

The results are colored in red.

Let's test an ERE pattern:

Get Mastering Linux Shell Scripting 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.