Format git log output with sed, awk, or the like
If I have output like this (from customized git log)
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
How could you pipe it through sed
, awk
or similar to achieve this output?
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
Here the only difference is that seconds and timezone are cut out from the date. Unfo开发者_开发百科rtunately, git doesn't seem to support custom date formats and I'm not good with the likes of sed
, so need some help.
I suggest using 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
awk version:
awk -F':[0-9][0-9] | ' '{$4=""}1' inputFile
test:
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
sed 's/:[^:]* -[^ ]*//' infile
Fixed (it's not a space, it's a tab).
精彩评论