I need to get the Date and commit results of a set of github in this format:
Date Commit
19 Mar 2015 b6959eafe0df6031485509c539e22eaf2780919c
1 Apr 2015 9a
You more-or-less never need grep | awk
as awk
can do the matching for you.
So grep Date: | awk '{print $4 " " $3 " " $6}'
can be rewritten as awk '/Date:/ {print $4 " " $3 " " $6}'
and grep commit | awk '{print $2}'
can be rewritten as awk '/commit/ {print $2}'
.
That should be enough to give you the first inklings of how to solve your problem.
Combine the awk scripts.
git log | awk '
# Print the header line (remove if you do not want it).
BEGIN {print "Date Commit"}
/^commit/ {
# Save the current commit
commit=$2
# Skip to the next line
next
}
/^Date:/ {
# Print the fields from the current line and the saved commit
print $4, $3, $6, commit
# Clear the saved commit Just in Case
commit=""
}
'
That being said you can get almost the format you want from git log
itself:
$ git log --format='%ad %H' --date=short
2015-03-19 b6959eafe0df6031485509c539e22eaf2780919c
2015-04-1 9a1f13339cc7d43930440c2350ea3060b72c8503
2015-04-1 1e76036421ca4d72c371182fc494af514911b099
Which you could convert to your desired output with some awk if you wanted. (Transposing the date fields is trivial, converting to the month names would require some more code/work.)