Difficulty: Easy
Correct Answer: wc infile >newfile
Explanation:
Introduction / Context:Shell redirection allows you to route the standard output of a command into a file. When obtaining counts from wc for a specific source, you can supply the filename as an argument or feed it via standard input; both produce valid results but with slightly different output formats. Understanding these nuances prevents surprises in scripts.
Given Data / Assumptions:
Concept / Approach:Using an explicit filename argument, wc infile > newfile runs wc on that file and writes the formatted counts (including the filename) into newfile. Supplying input via stdin, wc < infile > newfile also works but omits the filename in the report. The question asks for a command that sends the counts of the file to newfile; the explicit argument form is the most straightforward and commonly taught choice.
Step-by-Step Solution:
Create output: wc infile > newfileInspect: cat newfile to see counts with filename label.For a bare number, use options (for example, wc -l < infile > newfile).Integrate into scripts with test conditions as needed.Verification / Alternative check:Run wc infile and compare its terminal output to the contents of newfile; they should match exactly. Then try wc < infile > newfile to observe omission of the filename, illustrating the format difference.
Why Other Options Are Wrong:
Common Pitfalls:Overwriting newfile unintentionally (use >> to append), or confusing stdin redirection with argument-driven mode when you require the filename label in output.
Final Answer:wc infile >newfile
Discussion & Comments