Linux 技术手札

Linux 删除档案重复资料

如果想将档案内重复的资料删除, 在 Linux 下可以用 sort 及 uniq 指令完成, 例如以下 example.txt 档案内容是:

# cat example.txt
this is a testing.
abc def
abc def
this is a testing.

先用 sort 将档案内容排序, 再用 uniq 删除重复的资料:

# sort example.txt | uniq
abc def
this is a testing.

如果想将过滤了的内容储存, 可以这样:

# sort example.txt | uniq > example02.txt
# cat example02.txt
abc def
this is a testing.
Exit mobile version