cygwin uniq无法正常工作

时间:2015-01-26 16:40:51

标签: sorting cygwin uniq

给出以下排序文件(myfile.txt):

http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
http://quarterly.mayo.edu/photolisting/default.cfm?summary=&displaymode=&reporting_unit_code=

当我尝试:

uniq -c myfile.txt

我明白了:

21 http://quarterly.mayo.edu/photoListing/default.cfm?summary=&displaymode=&reporting_unit_code=
   1 http://quarterly.mayo.edu/photolisting/default.cfm?summary=&displaymode=&reporting_unit_code=

我猜这可能表示隐藏的角色或其他东西 - 但是当我尝试时:

uniq -u myfile.txt

我得到了预期的结果:

http://quarterly.mayo.edu/photolisting/default.cfm?summary=&displaymode=&reporting_unit_code=

这是一个真正的不一致,还是我错过了什么? 谢谢, 人

1 个答案:

答案 0 :(得分:1)

uniq -u仅打印唯一的行。您的myfile.txt显然有21条相同的行,后跟一条唯一行。 uniq -u仅打印一个唯一的行。

uniq myfile.txt应该打印两行,第一行对应21条相同的行,第二行对应最后的非匹配行。

例如:

$ ( echo foo ; echo foo ; echo bar ) | uniq -c
      2 foo
      1 bar
$ ( echo foo ; echo foo ; echo bar ) | uniq -u
bar
$

至于为什么uniq -c产生2行输出而不是1,它是因为你的最后一行与前面的21行不同。您在第22行上有photoListing(大写L),第22行有photolisting(小写l)。

(我的第一个想法是你可能在文件中有一些隐藏的字符;因为你在Cygwin上,不一致的行结尾是最可能的罪魁祸首。要查看隐藏的字符:

uniq -c myfile.txt | cat -A

但事实证明这不是问题。)