Text Manipulation Flashcards

1
Q

How to use the sed command to find and replace all the occurences of the term ‘mysql’ for ‘MySQL’ in a file called details.conf?

A
$ sed s/mysql/MySQL/g details.conf > details.conf
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to use the sed command to find and replace only the first occurence of the term ‘mysql’ for ‘MySQL’ in a file called details.conf?

A
$ sed s/mysql/MySQL/ details.conf > details.conf
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to use the sed command to find and replace only the second occurence of the term ‘mysql’ for ‘MySQL’ in a file called details.conf?

A
$ sed s/mysql/MySQL/2 details.conf > details.conf
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you display a file with line numbers?

A

Using the nl command.

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

How do you show only the first 20 lines of a file called text_file.txt?

A
$ head -20 text_file.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you show the last 20 lines of a file called text_file.txt?

A
$ tail -20 text_file.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why is the cat command not so good to display large files?

A

Because it prints all the file at once in the console making it not so practical to glean any information from it.

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

What utility does the man command use?

A

The “more” command.

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

What is the difference between “more” and “less” commands?

A

Both are used to display files page by page, but less has an additional functionality that permits filtering the text for terms.

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

After typing a term while seeing a file with less, how can you go to the next occurence of the searched term?

A

By pressing n.

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