Skip to main content

grep, awk, sed family tool

Grep

Global Regular Expression Pattern

With grep you can do simple text-based or regular expression search on the file you passed or can be also piped.

You can only provide in one pattern, you can provide in multiple pattern to search for by using the pipe symbol, but any parameter after the pattern are treated as filenames

Use the -E flag to use the extended regular expression notation, i.e. you don't have to escape the following character to get their special meaning, ?, +, {}, and | in the regular expression.

Usages

grep <insert word to search> filename This will perform a search on the entire file to find where the word occurs
grep -i <word> filename
Perform a case-insensitive search on the entire file
grep -R <word> .
Perform a search on all of the file in the current directory as well as the sub-directories
grep -c <word> filename
Count the number of matches
grep -A -B -C <word> filename
Use -A, -B, and -C to get context surrounding the matched text, after, before, and both before and after respectively

Awk