Chapter 4 - Working with Text Files Flashcards

1
Q

Which command to use on a text file to show the first 10 lines?

A

head

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

Which command to use on a text file to show the last 10 lines?

A

tail

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

Which option on tail or head command to be used to set the number of lines?

A

-n option. example : tail -n 5 /etc/passwd shows the last

five lines of the /etc/passwd file

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

What option to use along with tail command on any file that refreshes the display as new lines are added to the file?

A

-f option. Example : tail -f /var/log/messages

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

Which command is used to filter out a specific field?

A

cut command. -d option to specify the field delimiter followed by -f with the number of the specific field you want to filter out. Example : cut -d : -f 1 /etc/passwd

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

Which command is used to sort the contents of a file?

A

sort command. Example : sort /etc/passwd

cut -f 1 -d : /etc/passwd | sort

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

what option to use with sort command to specify which column you want to sort?

A

-k option. Example : sort -k3 -t : /etc/passwd. -t option is used to specify the delimiter

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

Which command to use to count words, lines and characters?

A

“wc” command

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

Which command to use to look for that specific string in the file?

A

grep command. Example : grep anna /etc/passwd

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

Which line anchor is used for looking for Lines Starting with a Specific Pattern?

A

Example : grep ^anna /etc/passwd

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

What is a Line Anchor?

A

The type of regular expression that specifies where in a

line of output the result is expected is known as a line anchor.

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

which regular expression to use that states that the line ends with some text?

A

$
For instance, the command
“grep ash$ /etc/passwd” shows all lines in the /etc/passwd file that end with the text
ash

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

Some of the most Significant Regular Expressions

A

Regular Expression Use
^text : Matches line that starts with specified text.
text$ : Matches line that ends with specified text.
. : Wildcard. (Matches any single character.)
[abc] : Matches a, b, or c.
* : Matches zero to an infinite number of the previous character.
{2} : Matches exactly two of the previous character.

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

Which are the other two text processing utilities?

A

sed

awk

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