我想要grep独特的路线。这是文件内容:
this is line 1
this is line 1
this is line 2
this is line 1
this is line 1
Run Code Online (Sandbox Code Playgroud)
我只想输出this is line 2到我的外壳。我怎样才能做到这一点?
sort x.txt |uniq -u
Run Code Online (Sandbox Code Playgroud)
假设您的文件在 x.txt 中,它给出
this is line 2
Run Code Online (Sandbox Code Playgroud)
小智 5
查看man uniq:
-u Only output lines that are not repeated in the input.
Run Code Online (Sandbox Code Playgroud)
考虑到这一点, sort 会进行成对比较以查看它的邻居是否匹配,这意味着您需要在将输出输入到 之前对输出进行排序uniq:
$sort my_list.txt | uniq -u