grep Flashcards

(55 cards)

1
Q

grep

A

displays lines in a file or stream that match a pattern expressed as a regular expression

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

grep command syntax

A

grep options ‘regular expression’ file(s)

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

-i

A

ignores case for matching

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

-v

A

Doesn’t display lines matching expression

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

-n

A

Displays line and n lines after matching lines (linux)

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

-c

A

Displays count of number of occurrences

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

-l

A

Displays list of filenames only

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

-e exp

A

Specifies given expression and can use multiple times

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

-x

A

Matches pattern with entire line (doesn’t match embedded patterns)

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

-f file

A

Takes pattern from file, one per line

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

-E or egrep

A

Treats pattern as an extended regular expression (ERE)

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

-F

A

Matches multiple fixed strings (in fgrep-style)

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

-A n

A

Display line and n lines after matching lines (linux)

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

-B n

A

Display line and n lines before matching line (linux)

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

matches a pattern at the beginning of a line

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

The caret has a triple role to play in regular expressions. When placed at the beginning of a character class (e.g., [^a-z]), it _____ every character of the class. When placed outside it, and at the beginning of the expression (e.g., ^2…), the pattern is matched at the ____ of the line. At any other location (e.g., a^b), it matches ____ literally.

A

The caret has a triple role to play in regular expressions. When placed at the beginning of a character class (e.g., [^a-z]), it negates every character of the class. When placed outside it, and at the beginning of the expression (e.g., ^2…), the pattern is matched at the beginning of the line. At any other location (e.g., a^b), it matches itself literally.

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

grep special character (for making Basic Regular Expressions)

The end of a line

A

$

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

*

A

zero or more occurrences of the previous character

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

grep special character

(for making Basic Regular Expressions)

a single character that is one of the ones listed in

A

[ ]

a single character that is one of the ones listed in
[ … ].

(similar to [ … ] for shell
file matching)

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

.

A

Matches single character

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

[abc]

A

a single character a, b, c

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

[c1-c2]

A

A single character with the ASCII range represented by c1 and c2

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

[^abc]

A

A single character that is not a, b, or

24
Q

^pat

A

Pattern pat at the beginning of a line

25
pat$
Pattern pat at the end of line
26
-F
Matches multiple fixed strings (in fgrep-style)
27
A regular expression uses an elaborate metacharacter set that overshadows the shell’s ____ _____.
A regular expression uses an elaborate metacharacter set that overshadows the shell’s wild cards.
28
Define: A regular expression
A regular expression uses an elaborate metacharacter set that overshadows the shell’s wild cards. grep uses this expression to match multiple similar patterns
29
Unlike wild cards, however, a regular expression is a feature of the _____ that uses it and has nothing to do with the _____. Quoting ensures that the _____ isn’t able to interfere and interpret the metacharacters in its own way.
Regular expressions are interpreted by the command and not by the shell. Quoting ensures that the shell isn’t able to interfere and interpret the meta-characters in its own way.
30
How does the command interpret the the following BRE: g*
Nothing or g, gg, ggg, etc
31
How does the command interpret the the following BRE: gg*
g, gg, ggg, etc
32
How does the command interpret the the following BRE: .*
Any number of characters, or none
33
How does the command interpret the the following BRE: [1-3]
A digit between 1 and 3
34
How does the command interpret the the following BRE: [^a-zA-Z]
A non alphanumeric character
35
How does the command interpret the the following BRE: bash$
bash at the end of a line
36
How does the command interpret the the following BRE: ^bash$
bash as the only word in line
37
How does the command interpret the the following BRE: ^$
Lines containing nothing
38
Define: a character class
A regular expression lets you specify a group of characters enclosed within a pair of rectangular brackets, [ ]. The match is then performed for any single character in the group. This form resembles the one used by the shell’s wild cards.
39
match a string beginning with e
ee*
40
How do you match trueman and truman from emp.1st
grep “true*man” emp.lst
41
How do you match match wilcocks and wilcox from emp.1st
grep “wilco[cx]k*s*” emp.lst The expression k*s* means that k and s may not occur at all (or as many times as possible); that’s why the expression used with grep also matches wilcox.
42
$
Matches a pattern at the end of a line
43
Extended regular expressions (ERE) make it possible to
match dissimilar patterns with a single expression.
44
The ERE set includes two special characters, (?) and (?). They are often used in place of the * to restrict the matching scope
+ & -
45
(egrep) +
Matches one or more occurrences of the previous character.
46
(egrep) ?
Matches zero or one occurrence of the previous character.
47
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk ch+
Matches one or more occurrences of character ch
48
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk ch?
Matches zero or more occurrence of character ch
49
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk exp1|exp2
Matches exp1 or exp2
50
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk (x1|x2)x3
Matches x1x3 or x2x3
51
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk g+
Matches at least one g
52
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk g?
Matches at least one g
53
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk g?
Matches nothing or one g
54
The Extended Regular Expression (ERE) Set Used by grep, egrep and awk GIF|JPEG
Matches GIF or JPEG
55
(lock|ver) wood
Matches lockwood or verwood