The Linux command line tool grep is your first step in learning regular expressions, or at least allowing you practice. It is a powerful tool that is as easy as -A -B and -C to use; we will see the switches later that put context to our searches and are often overlooked.
First we confirm that the use of fgrep and egrep in depreciated with grep containing:
- -E for enhanced regex
- -F for fast grep
Moving onto to the -i option to ignore case and the really useful -w to enable complete word search that saves us building word boundaries into the regex. If we need to reverse the search we can use -v for invert, however we also have the option -L that is useful when search multiple files to show those that don’t match as well as -l to show matching files.
We end up with the context switches
- -A3 show 3 lines after the match
- -B3 show three lines before
- -C3 show 3 lines before and after