Grep Flashcards

1
Q

Why would you use grep?

A

Grep is available on all computers with Unix/Linux, while Ack and Ag are not always available.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the basic usage of grep?

A

grep

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

By default, grep uses ______ to search for patterns in a file.

A

regular expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can we count the number of times a pattern is found in a file?

A

with the -c flag

grep -c ruby README.md

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can we display line numbers in the output of a grep search?

A

grep -n Ruby README.md

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can we perform a case-insensitive search with grep?

A

the -i flag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you use grep to search through multiple files?

A

Simply include all of the files you want to search within the command
grep rails README.md RELASING_RAILS.rdoc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What flag do we need to search through a directory?

A

The recursive flag (-R)

grep -R “Read” .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which flag can we use to narrow the search to file names within the directory with certain parameters?

A

grep -R –include=”*.yml” “Read” .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would you write grep -R –include=”*.yml” “Read” . in Ag?

A

ag Read -G yml$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can we search for lines in a file that don’t contain the letter a?

A

Using the invert search flag (-v)

grep -v “a” README.md

How well did you know this?
1
Not at all
2
3
4
5
Perfectly