Chapter 4 - Working with Text Files Flashcards
Which command to use on a text file to show the first 10 lines?
head
Which command to use on a text file to show the last 10 lines?
tail
Which option on tail or head command to be used to set the number of lines?
-n option. example : tail -n 5 /etc/passwd shows the last
five lines of the /etc/passwd file
What option to use along with tail command on any file that refreshes the display as new lines are added to the file?
-f option. Example : tail -f /var/log/messages
Which command is used to filter out a specific field?
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
Which command is used to sort the contents of a file?
sort command. Example : sort /etc/passwd
cut -f 1 -d : /etc/passwd | sort
what option to use with sort command to specify which column you want to sort?
-k option. Example : sort -k3 -t : /etc/passwd. -t option is used to specify the delimiter
Which command to use to count words, lines and characters?
“wc” command
Which command to use to look for that specific string in the file?
grep command. Example : grep anna /etc/passwd
Which line anchor is used for looking for Lines Starting with a Specific Pattern?
Example : grep ^anna /etc/passwd
What is a Line Anchor?
The type of regular expression that specifies where in a
line of output the result is expected is known as a line anchor.
which regular expression to use that states that the line ends with some text?
$
For instance, the command
“grep ash$ /etc/passwd” shows all lines in the /etc/passwd file that end with the text
ash
Some of the most Significant Regular Expressions
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.
Which are the other two text processing utilities?
sed
awk