Car*_*rum 4 unix git gnu sorting cut
今天我以为我在做一个简单的操作:
git blame file | sort -k 3
Run Code Online (Sandbox Code Playgroud)
获取file
按最后更改日期排序的所有行。不幸的是,它似乎没有正确排序。如果我执行以下操作,它确实有效:
git blame file | cut -c 20- | sort
Run Code Online (Sandbox Code Playgroud)
这只是将线路的第一部分砍掉,然后进行排序。该命令的成功表明,我认为sort
可以做实际上我是想操作。为什么不起作用?
这是来自输出的示例行git blame file
:
35d8e9eb (username 2007-01-17 03:58:04 +0000 155) Some text on line 155
Run Code Online (Sandbox Code Playgroud)
编辑:除了3
在原始命令行中使用任何合理的数字似乎工作正常 - 我可以按哈希(字段 1)、用户名(字段 2)、一天中的时间(字段 4)或行号(字段6),但日期(字段 3)不起作用 - 我根本无法确定它实际上以什么顺序结束......
编辑 2:我制作了一个显示相同问题的经过消毒的输入文件。这是cleaned.txt
:
cb7bb041 (eeeeeee 2010-12-14 19:41:18 +0000 42)
35d8e9eb (cccccccc 2007-01-17 03:58:04 +0000 135)
d7377fa9 (hhhhhhhh 2010-01-30 04:26:28 +0000 178)
Run Code Online (Sandbox Code Playgroud)
和输出sort -k 3 cleaned.txt
:
$ sort -k 3 cleaned.txt
cb7bb041 (eeeeeee 2010-12-14 19:41:18 +0000 42)
35d8e9eb (cccccccc 2007-01-17 03:58:04 +0000 135)
d7377fa9 (hhhhhhhh 2010-01-30 04:26:28 +0000 178)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,日期字段上的排序似乎根本没有发生。这是来自的输出cut -c 20- cleaned.txt | sort
:
$ cut -c 20- cleaned.txt | sort
2007-01-17 03:58:04 +0000 135)
2010-01-30 04:26:28 +0000 178)
2010-12-14 19:41:18 +0000 42)
Run Code Online (Sandbox Code Playgroud)
在这种情况下按日期排序工作正常!有什么建议?
我只是想通了。较短的用户名eeeeeee
意味着在日期字段之前有一个额外的空间。由于字段分隔符sort
是非空白到空白的转换,用户名较短的行的日期字段将该空格作为键字段的一部分,并首先排序。简单的修复:
git blame file | sort -b -k 3
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4539 次 |
最近记录: |