Text: grep
Grep is a tool to search for text within files.
Grep stands for Global Regular Expression Print.
grep "Fred" names.txt
Will search lines in the file named names.txt
and print any matching lines to
standard out.
Can use globs.
grep "Fred" *.md
Will search in all markdown files in the current directory.
Options:
-i
case insensitive-w
full words only-r
recursive search-v
invert the match-c
count matches-n
add line number of matches to output-l
only show names of files that match-c
show names of files that match with count of matches-B <num>
display<num>
lines before match, think of B as Before-A <num>
display<num>
lines after match, think of A as After-C <num>
display<num>
lines before and after match, think of C as Context
Combining with other tools
A common use case is to pipe the output of other commands to grep in order to search for something specific.
For example, piping the out put of history to grep to see your own commits.
history | grep "git commit"