Which UNIX command correctly changes the case of only the first three lines of the file "shortlist" from lower case to upper case?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. $ head -3 shortlist | tr '[a-z]' '[A-Z]'
Explanation
Thetr utility only ever reads from standard input and takes exactly two operands (the two character sets) — it does not accept a filename as a third operand, so any form that feeds tr a filename directly, like option (i)'s "tr '[a-z]' '[A-Z]' shortlist", is invalid. The correct approach is to first extract the required lines and then pipe them into tr: head -3 shortlist sends only the first three lines of the file to standard output, which tr '[a-z]' '[A-Z]' then converts to upper case, giving exactly the desired result. Options (iii) and (iv) jumble the command and argument order into syntactically meaningless invocations. Hence option (ii) is correct. More Software Engineering questions
- Match the following basic vi editor commands in UNIX with their functions. List I (Command): (a) dd (b) yy (c) p (d) u List II (Function):…
- Consider the following statements about linker software: (I) A linker combines multiple object (relocatable) modules into a single load mod…
- A distributed operating system typically consists of:
- Which of the following statements about UNIX signals is NOT correct?
- A null remote procedure call (RPC) (carrying 0 data bytes) takes 1.0 msec, with an additional 1.5 msec for every 1K of data carried. How lo…
- What is the function of the following UNIX command? wc -l a > b &