103.7 Search text files using regular expressions Flashcards

1
Q

What command do you usually use with regular expressions?

A

grep

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

What does a dot (.) represent in a regex?

A

A dot represents a single character. More than one dot can be used consecutively to represent more unknown characters in a row.

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

What symbol do you use to search for a string at the beginning of a line and at the end of a line in a regex?

A

At the beginning: ^

At the end: $

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

What syntax would you use to search for a line that contains a specified character using a regex?

A

grep [x]

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

What syntax would you use to search for a line that contains a string at the end using a regex?

A

grep bash$

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

What syntax would you use to search for a line that contains a string the beginning using a regex?

A

grep ^rpc

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

What syntax would you use to search for a line that contains either a capital or a lowercase character using a regex?

A
#grep -i [x] 
#grep [Xx]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What syntax would you use to search for a line in a file that begins with either a capital or lowercase A, then followed by any character and the third character being either a capital or lowercase A?

A
#grep ^[Aa] .[Aa] 
$grep -i ^[a].[a]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What symbols do you use to exclude a character from a search in a regex?

A

[^abc]

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

What does the star sign mean in a regex?

A

It matches zero or more of the preceding characters or expression.

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

What does the #egrep command do?

A

It searches a specified file line by line returning lines that contain a pattern matching a given regular expression.

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

What is the equivalent of egrep?

A

grep -E

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

How do you egrep a file for lines that contain {bash} at the end of the lines?

A

egrep ‘bash$’

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

How do you egrep a file just to know how many lines contain the string at the end of the lines?

A

egrep -c ‘bash$’

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

How do you egrep a file to find lines that contain a string at the beginning or another string at the end of the lines?

A

egrep ‘^rpc|nologin$’

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

What does the fgrep command do?

A

It searches based on strings rather than patterns. Also uses file globbing instead of regexes.
It equals to grep -F

17
Q

What is the syntax for the #sed command to replace a string for another globally in a whole document?

A

sed ‘s/orignalstring/newstring/g’

18
Q

In the #sed command, what flag do you use to make the stream search case insensitive? What flag do you use to prevent another file being created?

A
#sed -I (case insensitive)
#sed -i (in place)
19
Q

What is the syntax for the #sed command to make a change permanent in a file?

A

sed -i ‘s/orignalstring/newstring/g’

20
Q

What is the syntax for the #sed command?

A

sed ‘s/orignalstring/newstring/’

21
Q

What is the command that is usually used to search and replace words in a file?

A

sed