By default grep uses what it calls BRE or basic regular expressions: in this mode only some meta-characters (characters with a special meaning inside a regular expression) are available.Īs a first example we will try to use grep to match a very simple string, the word “mortal”. The Basic regular expression modeĪ regular expression is a pattern constructed following specific rules in order to match a string or multiple strings. Before we start explaining in what those variants are different from the original we must examine the default grep behavior when using regular expressions. These variants are actually deprecated, since they are the equivalent of running grep with the -E and -F options respectively. In the introduction we spoke about two grep variants: egrep and fgrep.
![grep regexp grep regexp](https://qwer.linuxfordevices.com/wp-content/uploads/2020/03/Grep-command-in-Linux.png)
One Ring to bring them all, and in the darkness bind them, One Ring to rule them all, One Ring to find them, In the Land of Mordor where the Shadows lie. Seven for the Dwarf-lords in their halls of stone, We will put this really famous excerpt from the book “The Lord Of The Rings” on a file, and we will use as a target for our examples: Three Rings for the Elven-kings under the sky,
![grep regexp grep regexp](https://cdn.webservertalk.com/wp-content/uploads/page5-29-768x274.png)
GREP REGEXP HOW TO
In this tutorial we will see how to use it, and we will examine also its variants: egrep and fgrep. Grep is one of the most useful tools we can use when administering a unix-based machine: its job is to search for a given pattern inside one or more files and return existing matches. After reading this tutorial you should be able to understand how the grep command works, and how to use it with basic and extended regular expressions.