Grep and Regular Expressions Flashcards

1
Q

What does grep do

A

Prints lines that match defined pattern

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

How do you use grep to search case insensative

A

grep -i “search pattern”

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

Shows lines not containing pattern

A

grep -v

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

Search for pattern in filename

A

grep error /var/log/messages

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

Search for lines starting with error

A

grep “^error” /var/log/messages

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

Search for lines ending with error

A

grep “error$” /var/log/messages

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

Search for all characters except (aeiou)

A

grep “[^aeiou]” /var/log/messages

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

Search for the pattern error and Error

A

grep [eE]rror /var/log/messages

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

Search for empty lines

A

grep “^$” /var/log/messages

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

Search for only un-commented lines

A

grep -v ^# /etc/ssh/sshd_config

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

What is egrep

A

same as grep but using extended regular expressions

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

What is fgrep

A

interprets patterns as list of fixed strings

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