Grep Flashcards
Why would you use grep?
Grep is available on all computers with Unix/Linux, while Ack and Ag are not always available.
What is the basic usage of grep?
grep
By default, grep uses ______ to search for patterns in a file.
regular expressions
How can we count the number of times a pattern is found in a file?
with the -c flag
grep -c ruby README.md
How can we display line numbers in the output of a grep search?
grep -n Ruby README.md
How can we perform a case-insensitive search with grep?
the -i flag
How can you use grep to search through multiple files?
Simply include all of the files you want to search within the command
grep rails README.md RELASING_RAILS.rdoc
What flag do we need to search through a directory?
The recursive flag (-R)
grep -R “Read” .
Which flag can we use to narrow the search to file names within the directory with certain parameters?
grep -R –include=”*.yml” “Read” .
How would you write grep -R –include=”*.yml” “Read” . in Ag?
ag Read -G yml$
How can we search for lines in a file that don’t contain the letter a?
Using the invert search flag (-v)
grep -v “a” README.md