sorted-status.txt is sorted so identical status names are adjacent.
Display each status and its consecutive occurrence count.
Which command is appropriate?
uniq -c collapses adjacent identical lines and prefixes each group with its count.
Detailed explanation
uniq -c sorted-status.txtCorrect. uniq -c groups adjacent equal lines and prints their counts.
Correct. uniq -c groups adjacent equal lines and prints their counts.
sort -c sorted-status.txtIncorrect. sort -c checks ordering but does not count groups.
Incorrect. sort -c checks ordering but does not count groups.
wc -l sorted-status.txtIncorrect. wc -l reports only the total line count.
Incorrect. wc -l reports only the total line count.
uniq -d sorted-status.txtIncorrect. uniq -d prints duplicate lines but does not show their counts.
Incorrect. uniq -d prints duplicate lines but does not show their counts.
Try it yourself
An example you can run in a temporary verification environment.
printf 'down\ndown\nup\nup\nup\n' | uniq -cExpected result
2 downと3 upKey points
- uniq handles adjacent duplicates
- -c prints counts
- Sort first when needed
Notes
- Environment: GNU coreutils 9.x / 標準入力
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.