- Home
- Server Administration
- LPIC-1 Linux Administrator 101
16.
Which of the following commands will number the lines in aleph.txt? (Select three.)
- A.fmt aleph.txt
- B.nl aleph.txt
- C.cat -b aleph.txt
- D.cat -n aleph.txt
- E.od -nl aleph.txt
- Answer & Explanation
- Report
Answer : [B, C and D]
Explanation :
Explanation :
The nl command numbers lines, so it does this task without any special options, and option B is correct. (Its options can fine-tune the way it numbers lines, though.) The cat command can also number lines via its -b and -n options; -b numbers non-blank lines, whereas -n numbers all lines (including blank lines). Thus, options C and D are both correct. Neither the fmt command nor the od command will number the lines of the input file, so options A and E are both incorrect. |
17.
Which of the following commands will change all occurrences of dog in the file animals
.txt to mutt in the screen display?
- A.sed –s “dog” “mutt” animals.txt
- B.grep –s “dog||mutt” animals.txt
- C.sed ‘s/dog/mutt/g’ animals.txt
- D.cat animals.txt | grep –c “dog” “mutt”
- E.fmt animals.txt | cut ‘dog’ > ‘mutt’
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The sed utility can be used to “stream” text and change one value to another. In this case, the s option is used to replace dog with mutt, making option C correct. The syntax in option A is incorrect, and choices B and D are incorrect because grep doesn’t include the functionality needed to make the changes. Option E combines fmt, cut, and redirection in a way that simply won’t work to achieve the desired goal. |
18.
You’ve received an ASCII text file (longlines.txt) that uses no carriage returns within
paragraphs but two carriage returns between paragraphs. The result is that your preferred
text editor displays each paragraph as a very long line. How can you reformat this file so
that you can more easily edit it (or a copy)?
- A.sed ‘s/Ctrl-M/NL/’ longlines.txt
- B.fmt longlines.txt > longlines2.txt
- C.cat longlines.txt > longlines2.txt
- D.pr longlines.txt > longlines2.txt
- E.grep longlines.txt > longlines2.txt
- Answer & Explanation
- Report
Answer : [B]
Explanation :
Explanation :
The fmt command performs the desired task of shortening long lines by inserting carriage returns. It sends its results to standard output, so option B uses output redirection to save the results in a new file. The sed command of option A won’t accomplish anything useful; it only replaces the string Ctrl-M with the string NL. Although these strings are both sometimes used as abbreviations for carriage returns or new lines, the replacement of these literal strings isn’t what’s required. Option C creates an exact copy of the original file, with the long single-line paragraphs intact. Although option D’s pr command is a formatting tool, it won’t reformat individual paragraphs. It will also add headers that you probably don’t want. Option E’s grep command searches for text within files; it won’t reformat text files. |
19.
Which of the following commands will print lines from the file world.txt that contain
matches to changes and changed?
- A.grep change[ds] world.txt
- B.sed change[d-s] world.txt
- C.od “change’d|s’” world.txt
- D.cat world.txt changes changed
- E.find world.txt “change(d|s)”
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
The grep utility is used to find matching text within a file and print those lines. It accepts regular expressions, which means you can place in brackets the two characters that differ in the words for which you’re looking. Thus, option A is correct. The syntax for sed, od, cat, and find wouldn’t perform the specified task, so options B through E are all incorrect. |
20.
Which of the following regular expressions will match the strings dog, dug, and various
other strings but not dig?
- A.d.g
- B.d[ou]g
- C.d[o-u]g
- D.di*g
- E.d.ig
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The bracket expression within the d[o-u]g regular expression in option C means that any three-character string beginning in d, ending in g, and with the middle character being between o and u will match. These results meet the question’s criteria. Option A’s dot |