Chapter 3 - grep Flashcards

1
Q

What does grep stand for?

A

Global regular expression print

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

What is grep used for?

A

grep searches text or files for a given string or pattern of text.

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

Explain grep option -w and how would you type it out?

A

Searches only for the exact word.
grep -w “the” resume.txt
(so it Won’t bring up words there or these)

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

Explain these grep options -l -c

A
  • l shows just a list of the text file with matches. ( no lines of text)
  • c similar to the -l option but adds a number with how many matches found in the file. (ex. blah.txt :7 )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What option in grep would you use to search subdirectories as well?

How would you type this command out?

A

-r the recursive option also searches subdirectories.

grep -winr “dairy” .

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

How do you use grep to search every file in the current working directory?

A

grep -win “john” ./*

you can also specify to search all .txt files in the directory.
grep -win “john” ./*.txt

Keep in mind you can join options together.
grep -win “test” poems.txt

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

Explain the grep -n option.

A

grep -n “test” poems.txt

Adds the number of the line to the out put.

Keep in mind you can join options together.
grep -win “test” poems.txt

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

Explain the grep -i option.

A

grep -i Makes the search Non case sensitive.

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

Explain the grep -v option.

A

grep -v Omits all the lines with that search ( grep -v “blah” poem.txt )

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

Explain these grep options

-B 4 -A 5 -C 2 And type out the command.

A
  • B 4 Shows the first 4 lines of text Before our search match.
  • A 5 Shows the last 5 lines of text After our search match.
  • C 2 Shows the first 2 and last 2 line of our search option.

grep -win -A 5 “john” poems.txt

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

If cat is hung (flashing cursor & just repeating lines) how do you exit?

A

ctrl and D

We can also create a basic text file by

cat lazy dog.txt
the lazy dog blah blah
ctrl D (to exit)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly