如何删除文件中一列中重复的数字?

zar*_*ara 4 linux text

我有一个文件看起来像:

输入:

34
34
34
43
54
54
10001
10001
10001
10001
100005
100005
500000
Run Code Online (Sandbox Code Playgroud)

所以我需要每个数字只出现一次:

出去:

34
43
54
10001
100005
500000
Run Code Online (Sandbox Code Playgroud)

考虑到真实文件很大,重复次数太多,有什么建议吗?

小智 6

这个给你:

$ uniq inputFile > outputFile
Run Code Online (Sandbox Code Playgroud)

但注意uniq只会删除那些接连不断的重复行。因此,如果您想删除所有重复行,即使是那些不连续的行,您可以首先sort输入文件并使用uniq

$ sort -g inputFile | uniq > outputFile
Run Code Online (Sandbox Code Playgroud)

-g 选项将根据一般数值进行比较。

或者只是使用 sort -nu inputFile > outputFile