执行uniq
命令前,需要先用sort
命令做排序,否则很有可能uniq
会失效,因为uniq
只会对相邻的内容做合并。
Linux manual
Note: ‘uniq’ does not detect repeated lines unless they are adjacent. You may want to sort the input first, or use ‘sort -u’ without ‘uniq’. Also, comparisons honor the rules specified by ‘LC_COLLATE’.