nerdexam
CompTIA

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…

System Management

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)
  • A
    4% (1)
  • B
    7% (2)
  • D
    89% (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

#Linux Commands#Text Processing#tr command#Shell Redirection

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice