使用sed,awk等格式化git log输出

时间:2011-09-22 19:13:23

标签: git formatting sed awk

如果我有这样的输出(来自自定义git日志)

d1fd022 2011-09-21 17:02:26 -0400       Replace double quotes with single quotes.
7227fe4 2011-09-21 13:57:36 -0400       Add automatic CommandTFlush to mkdir/rm/touch/cd

你怎么能通过sedawk或类似方式来管理它以实现此输出?

d1fd022 2011-09-21 17:02       Replace double quotes with single quotes.
7227fe4 2011-09-21 13:57       Add automatic CommandTFlush to mkdir/rm/touch/cd

这里唯一的区别是从日期中删除了秒和时区。不幸的是,git似乎不支持自定义日期格式,我对sed之类的东西不太好,所以需要一些帮助。

3 个答案:

答案 0 :(得分:2)

我建议使用cut(POSIX):

[guest@pawel] ~ $ cut -c 1-24,34- foo.txt  
d1fd022 2011-09-21 17:02       Replace double quotes with single quotes.
7227fe4 2011-09-21 13:57       Add automatic CommandTFlush to mkdir/rm/touch/cd

答案 1 :(得分:1)

awk版本:

awk -F':[0-9][0-9] | ' '{$4=""}1' inputFile

<强>试验:

kent$  echo "d1fd022 2011-09-21 17:02:26 -0400       Replace double quotes with single quotes.
7227fe4 2011-09-21 13:57:36 -0400       Add automatic CommandTFlush to mkdir/rm/touch/cd"|awk -F':[0-9][0-9] | ' '{$4=""}1'

d1fd022 2011-09-21 17:02        Replace double quotes with single quotes.
7227fe4 2011-09-21 13:57        Add automatic CommandTFlush to mkdir/rm/touch/cd

答案 2 :(得分:0)

sed 's/:[^:]* -[^     ]*//' infile

修正(它不是空格,它是标签)。