gpt4 book ai didi

macos - `uniq` 未按预期工作

转载 作者:行者123 更新时间:2023-12-05 00:41:36 25 4
gpt4 key购买 nike

我有一个名为“test.txt”的文件,如下所示:

10
10
10
8
10
9
10
10
9
10
8

由于某种原因,当我运行 uniq test.txt 时,我得到了以下输出:

10
8
10
9
10
9
10
8

为什么我会得到这个输出?我正在使用 BSD uniq。程序中是否存在某种错误?

最佳答案

我不是专家,但我很确定 uniq 只比较相邻的行。我不必经常使用它,但是在我的系统上运行 man uniq 我得到:

The uniq utility reads the specified input_file comparing adjacent lines, and writes a copy of each unique input line to the output_file. If input_file is a single dash (`-') or absent, the standard input is read. If output_file is absent, standard output is used for output. The second and succeeding copies of identical adjacent input lines are not written. 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.

因此它们必须相邻才能被检测到。因此,反复报道。它们与相邻的行不同,这都是 uniq 实际测试的。

希望对您有所帮助。让我知道我是否错过了什么,我其实也有点好奇。

关于macos - `uniq` 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26248037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com