Basic regular expressions
You have a problem and you want to solve it with regular expressions? Now you have two problems! This is just one of the many regular expression jokes on the Internet.
In this section, you will learn how regular expressions work, as we will be using them in the upcoming chapters. We have prepared a file for our playground and if you want to try the grep commands on your own, you can take it from the GitHub repository.
Let's start by opening our text file so we can see its contents, and then splitting the screen so we can see both the file and the command side by side.
First of all, the simplest and probably the most common regular expression is to find a single word.
For this we will use the grep "joe" file.txt
command:
joe
is the string we are searching for and file.txt
is the file where we perform the search. You can see that grep printed the line that contained our string and the word is highlighted with another color. This will only match the exact...