grep is a command line tool used for finding lines of text in a file or stream.

-- find text in file
grep foo *.txt

-- find lines that don't have the text
grep -v foo *.txt

-- case insensitive
grep -i foo *.txt

-- from stdin
echo access.log | grep foo

-- recursive search subdirs
grep -r foo *.txt

-- print filenames only
grep -l foo *.txt

-- print 3 lines before and 2 lines after matching line
grep -B 3 -A 2 foo *.txt

-- find lines starting with a capital letter
grep '^[A-Z]' *.txt

-- find lines with either of the names
egrep 'Nic|Koen' *.txt

Normally, the data sent to grep is finite and delimited. Grep will return its results after it sees the end of file. Sometimes you want to grep something out of an infinite stream … say the stdout of a long running process on a remote server. In these cases, you need to tell grep to return results per line.

kubectl logs svc-pod | grep --line-buffered "wp-admin"