对列表进行排序,保留每个重复行中的一个条目

use*_*691 4 command-line

我有一份我每天下载的电影列表,格式如下

act-of-valor-2012
act-of-valor-2012
the-possession-2012
the-possession-2012
american-crude-2008
american-crude-2008
when-strangers-appear-2001
like-father-like-son-2005
like-father-like-son-2005
get-him-to-the-greek-2010
get-him-to-the-greek-2010
wall-street-money-never-sleeps-2010
wall-street-money-never-sleeps-2010
christmas-evil-1980
days-of-glory-1944
Run Code Online (Sandbox Code Playgroud)

我需要保持相同的顺序,但删除 dupl.icate 行,使其成为

act-of-valor-2012
the-possession-2012
american-crude-2008
when-strangers-appear-2001
like-father-like-son-2005
get-him-to-the-greek-2010
wall-street-money-never-sleeps-2010
christmas-evil-1980
days-of-glory-1944
Run Code Online (Sandbox Code Playgroud)

排序更改顺序任何人有任何想法我如何才能做到这一点?

谢谢

Jos*_*Jos 6

你想要uniq命令。

来自man uniq

 Filter adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output).

       With no options, matching lines are merged to the first occurrence.
Run Code Online (Sandbox Code Playgroud)

使用方法如下:

uniq movies.txt

根据需要输出。