Global Regular Expression Print
grep
Print lines from text that match patterns, basic regex is used by default
Use
grep /etc/ssh/sshd_config pattern match pattern in /etc/sshd_config, case sensitive
3 characters before and 4 characters after
echo "some123_string_and_another" | grep -o -P '.{0,3}string.{0,4}'
result: 23_string_and
Useful Flags
-E use extended regex
-A x print x lines after matched pattern
-B x print x lines before matched pattern
-C x print x lines before and after matched pattern, results separated by "--"
-c print number of matches
-i case insensitive
-mX limit number of matches to X
-n print line number from file
-o only print matched pattern
-R recursive search in a given folder, follow symlinks
-r recursive search in a given folder, don't follow symlinks
-v match inverse
-w match whole words only