如何删除重复的行但不排序(保持初始顺序)

时间:2018-06-11 12:35:57

标签: linux sorting terminal text-processing data-processing

我有这个输入:

Host: ping.chartbeat.net
Host: extra.test.co
userblablabla
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: extra.test.co
Host: secure.test.com
userlalalalala
Host: ping.chartbeat.net
Host: secure.test.com
Host: secure.test.com
Host: secure.test.com

我希望将其转换为:

Host: ping.chartbeat.net
Host: extra.test.co
userblablabla
Host: secure.test.com
userlalalalala

我该如何表现呢?

我尝试了|sort -u,但这打破了我想要行的顺序

1 个答案:

答案 0 :(得分:1)

您想使用uniq <file>uniq is part of the GNU coreutils