Reputation: 13
I had a midterm exam and one of the questions were:
what does the following command do step by step: cat file1.txt | wc | wc -w > file2
Then What would be displayed on the standard out of "cat file2"
For the first part: I wrote that cat temp.txt stores all of the lines of file1.txt into an output, and that output goes through the word count pipe, which turns the output into # of lines, # of words, and number of characters. This output then turns into an input for wc -w which filters out everything except for the number of words. Finally the number of words get inputed into a file called file1
For second part: I wrote that cat file2 will display the number of words in file1.txt
they didn't give me an explanation and just marked it wrong so i'm wondering if anyone can give me some insight?
Upvotes: 0
Views: 3627
Reputation: 36685
The wc utility displays the number of lines, words, and bytes. This means that cat file1.txt | wc | wc -w
has to return 3 for any input file file1.txt
.
Upvotes: 3