Grep - an introduction
grep is a Linux/Unix shell tool that allows you to search in text files. Through piping, you can also use it to search through the output printed to screen from another command. Most of what I use grep for is that.
General search syntax is
grep "<search string>" <file.txt>
Grep will return any lines that contain the full or substrings of it.
You can pass the output of a previous command to grep using the pipe
| operator, like so:
$ argo list -n <namespace> --running | grep "fire-season-full" fire-season-full-ca-nox fire-season-full-ca-co2 ...
You can pipe any number of times. You can pipe
grep to another
grep, which leads to some very powerful workflows.
(base) ➜ $ history | grep "git commit -m" | grep "error" 859 git commit -m "chore(test):[READY-220] fix lint errors"
history feature of zsh returns the last
1000 commands ran in terminal. We extract just the
git commit commands. Of the result, we extract any line that spoke about an
|Search whole string||
|Case insensitive search||
|Show line numbers||
|Search all text files in a dir recursively||
|Search files, but only return number of hits, not every hit in a file||
Grep allows you to combine options with a single hyphen. Although this makes the command less readable, it is still a valid syntax.
Do case insensitive search of the full search term. Show results with line numbers
$ grep -win "<search term>" file.logs > 51:search term > 99:search TERM