首页 > 解决方案 > 从文本文件中仅删除顺序重复?

问题描述

我只是一揽子删除重复项没有问题- sort -u input.txt > output.txt 很容易做到这一点。但我只想删除顺序的、后续的重复项,我不知道该怎么做。这是一个例子:

输入:

One
Two
Two
Three
Four
Five
Five
Six
Seven
Seven
Seven
Three
Three
Two
One

输出:

One
Two
Three
Four
Five
Six
Seven
Three
Two
One

有没有人想出一个简单的 bash 序列来做到这一点,或者知道一个 *NIX 命令行实用程序可以做到这一点?

编辑:澄清了这个例子。

标签: linuxbashshellzsh

解决方案


推荐阅读