从文本文件中删除重复的行

时间:2013-06-20 09:38:17

标签: shell command-line ssh command

我正在尝试从文件中删除所有重复的行并使用此命令:

sort text.txt | uniq -u > ALL.txt

但是我收到了这个错误:

sort: string comparison failed: Invalid or incomplete multibyte or wide character
sort: Set LC_ALL='C' to work around the problem.
sort: The strings compared were `http://lestarsmagazine.com/2011/10/07/adja-ndoye-ex-mannequin-\253-balla-gaye-adja-diallo-mara-ndiaye-l\222alcool-la-drogue-et-moi-\273/2691278-3806038/ | 0\r' and `http://sopfree.com/slight-conditioning/ | 0\r'.

我需要更改命令才能解决此问题?

2 个答案:

答案 0 :(得分:3)

LC_ALL='C' sort text.txt | LC_ALL='C' uniq > ALL.txt

编辑:删除了'-u'。根据您的描述,听起来您不应该使用它。您可能误解了手册页。该选项将跳过输入中的非唯一行而不是合并它们。

答案 1 :(得分:0)

问题不在于您的命令不正确,而在于您的数据。从错误中,text.txt中的行分隔符看起来不正确或受损。我强烈建议您查看您的数据(即使只是在文本编辑器中打开并再次将其保存回来可能会修复它)或在此处发布,以便其他人可以查看它。

相关问题