行长计数bash

use*_*648 0 bash awk uniq

如果我有一个包含的示例文件

11
11
0
11
11
11
11
0
Run Code Online (Sandbox Code Playgroud)

并运行uniq -c命令为什么它给我输出

2 11
1 0
4 11
1 0
Run Code Online (Sandbox Code Playgroud)

代替

6 11
2 0
Run Code Online (Sandbox Code Playgroud)

如何将输出设置为上述而不是将其分成奇怪的组

dev*_*ull 5

您的问题已在手册中得到解答.输入需要排序.

The uniq utility reads the standard input comparing adjacent lines, and
writes a copy of each unique input line to the standard output.  The sec-
ond and succeeding copies of identical adjacent input lines are not writ-
ten.  Repeated lines in the input will not be detected if they are not
adjacent, so it may be necessary to sort the files first.
Run Code Online (Sandbox Code Playgroud)

说:

sort inputfile | uniq -c
Run Code Online (Sandbox Code Playgroud)