Difference between revisions of "Global Regular Expression Print"
(→Use) |
|||
| Line 5: | Line 5: | ||
== Use == | == Use == | ||
<code>grep /etc/ssh/sshd_config pattern</code> match pattern in /etc/sshd_config, case sensitive</br> | <code>grep /etc/ssh/sshd_config pattern</code> match pattern in /etc/sshd_config, case sensitive</br> | ||
</br> | |||
3 characters before and 4 characters after</br> | |||
<code>echo "some123_string_and_another" | grep -o -P '.{0,3}string.{0,4}'</code></br> | |||
result: 23_string_and</br> | |||
== Useful Flags == | == Useful Flags == | ||
Latest revision as of 15:44, 1 July 2025
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