XK0-005 · Question #874
A Linux administrator needs to replace all lowercase words with uppercase words and save the changes in a text file. Which of the following commands will help the administrator accomplish this task?
The correct answer is D. cat lowercase.txt | tr a-z A-Z >> uppercase.txt. The 'tr' (translate) command uses the syntax 'tr set1 set2' to translate characters. 'cat lowercase.txt | tr a-z A-Z >> uppercase.txt' correctly translates all lowercase a-z characters to uppercase A-Z and appends the result to uppercase.txt. Option A uses '[:lower:]' and…
Question
A Linux administrator needs to replace all lowercase words with uppercase words and save the changes in a text file. Which of the following commands will help the administrator accomplish this task?
Options
- Acat lowercase.txt | tr [:lower:] [:UPPER:] >> uppercase.txt
- Bcat lowercase.txt | tr {:lower:} {:upper:} >> uppercase.txt
- Ccat lowercase.txt | tr [a-z] : [A-Z] >> uppercase.txt
- Dcat lowercase.txt | tr a-z A-Z >> uppercase.txt
How the community answered
(28 responses)- A4% (1)
- B7% (2)
- D89% (25)
Explanation
The 'tr' (translate) command uses the syntax 'tr set1 set2' to translate characters. 'cat lowercase.txt | tr a-z A-Z >> uppercase.txt' correctly translates all lowercase a-z characters to uppercase A-Z and appends the result to uppercase.txt. Option A uses '[:lower:]' and '[:UPPER:]' - the POSIX class name must be all lowercase, so '[:upper:]' is correct, not '[:UPPER:]'. Option B uses double curly braces which is invalid syntax. Option C places a colon between the two sets, which is incorrect syntax for tr.
Topics
Community Discussion
No community discussion yet for this question.