仅打印文件中的唯一行而不是重复行

3 sed awk perl text-processing

我有一个按行排序的单词列表,如下所示:

apple
apple
grapes
lime
orange
orange
pear
pear
peach
strawberry
strawberry
Run Code Online (Sandbox Code Playgroud)

我只想打印出唯一的行并删除重复项:

grapes
peach
lime
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点sedawk或者perl

cuo*_*glm 10

这就是uniq的工作:

$ LC_ALL=C uniq -u file
grapes
lime
peach
Run Code Online (Sandbox Code Playgroud)

如果您需要其他工具,例如perl

perl -nle '$h{$_}++; END {print for grep { $h{$_} == 1 } %h}' <file
Run Code Online (Sandbox Code Playgroud)