linux - 为什么我需要对 uniq 进行排序以删除重复行?

标签 linux shell sorting uniq

我想查看文件的唯一行(只出现一次的行)但以下命令显示重复行:

uniq -u data.txt 
#(it shows repeated lines)

我搜索了一下,发现如果你输入 sort 就可以,但为什么呢?

sort data.txt | uniq - u 
#(it works, only shows unique lines)

最佳答案

它在手册页中是明确的:

Repeated lines in the input will not be detected if they are not adja- cent, so it may be necessary to sort the files first.

关于linux - 为什么我需要对 uniq 进行排序以删除重复行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38506066/

相关文章:

php - smartctl 不能从 cron 工作

azure - 如何将 az keyvault Secret list -o table 输出存储在数组中? Azure CLI、Shell 脚本

jquery - 数据表按数字对字符串进行排序

c++ - 如何从数组 C++ 中获取唯一字符串

c - 来自变量的 Bash 脚本 printf 颜色?

linux - 根据不在固定位置的字段对文件进行排序

linux - 在 Linux (Ubuntu) 中编译基本 C 语言 CUDA 代码

linux - Android SDK 网络浏览器

c# - Mono,asp.net C#和MVC的操作方法和教程

linux - 获取 tar 存档中特定文件的内容