简体   繁体   English

在外壳中排序git timestamp

[英]Sorting git timestamp in the shell

I have a list of Git timestamps in the format Mon Jan 1 01:01:01 2013 +0500 . 我有格式为Mon Jan 1 01:01:01 2013 +0500的Git时间戳列表。 I need sort them in the shell somehow and have no clue how to approach this. 我需要以某种方式在外壳中对它们进行排序,并且不知道如何进行处理。 So far I've created two arrays - one for months and one for days. 到目前为止,我已经创建了两个数组-一个数组几个月,一个数组几天。

Any suggestions? 有什么建议么?

Thanks. 谢谢。

EDIT: This is not a git log that I'm going through, this is just a bunch of git timestamps that I have pulled out from different repos. 编辑:这不是我正在经历的git日志,这只是我从其他存储库中提取的一堆git时间戳。

You can use date to convert to a format that's easier to sort, such as epoch . 您可以使用date转换为更易于排序的格式,例如epoch I'll assume you have a file called dates.in , with one date per line. 我假设您有一个名为dates.in的文件,每行一个日期。

#!/bin/bash

while read d; do
    date -d "$d" +%s
done <dates.in | sort | \
while read d; do
    date -d "@$d"
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM