bash - Output using awk in a pattern of svn log -
how modified , added files revision,author , comments svn log verbose in pattern:
cat test:
r7351 | user01 | 2013-07-02 17:53:28 -0400 (tue, 02 jul 2013) | 2 lines changed paths: d /trunk/demo/proj1/.project jira-125723 removing unwanted files ------------------------------------------------------------------------ ------------------------------------------------------------------------ r7352 | user02 | 2013-07-02 17:54:24 -0400 (tue, 02 jul 2013) | 2 lines changed paths: d /trunk/demo/proj2/320-test.ert jira-125723 removing unwanted files ------------------------------------------------------------------------ ------------------------------------------------------------------------ r7504 | user04 | 2013-07-08 14:26:36 -0400 (mon, 08 jul 2013) | 4 lines changed paths: m /trunk/demo/maven/sum.jsp m /trunk/demo/code/results.jsp jira-121639 wp-iqisu- lot of changes fix issue ------------------------------------------------------------------------ ------------------------------------------------------------------------ r7523 | user08 | 2013-07-08 16:17:52 -0400 (mon, 08 jul 2013) | 1 line changed paths: /trunk/demo/ant/properties jira-2185[/code]
my code , output:
cat test | awk '/^r[0-9]* \|/ { revision=$1; } / [am]/ { print revision": "$0; }' r7504: m /trunk/demo/maven/sum.jsp r7504: m /trunk/demo/code/results.jsp r7523: /trunk/demo/ant/properties[/code]
but need author , comments information too. desired output:
r7504: user04 jira-121639 modified /trunk/demo/maven/sum.jsp wp-iqisu- lot of changes fix issue r7504: user04 jira-121639 modified /trunk/demo/code/results.jsp wp-iqisu- lot of changes fix issue r7523: user08 jira-2185 added /trunk/demo/ant/properties
$ cat tst.awk begin{ rs="\n-+\n"; fs="\n"; ofs="\t" } /\n [ma]/ { sub(/^-+\n/,"") sub(/[[:space:]]+$/,"") split($1,hdr,/ \| /) numfiles=0 (i=3;$i;i++) { sub(/^ +m +/,"modified" ofs,$i) sub(/^ +a +/,"added" ofs,$i) file[++numfiles] = $i } user = $(i + 1) sub (/\[.*/,"",user) cmts = $(i + 3) (filenr=1;filenr<=numfiles;filenr++) { print hdr[1], hdr[2], user, file[filenr], cmts } } $ $ awk -f tst.awk file r7504 user04 jira-121639 modified /trunk/demo/maven/sum.jsp wp-iqisu- lot of changes fix issue r7504 user04 jira-121639 modified /trunk/demo/code/results.jsp wp-iqisu- lot of changes fix issue r7523 user08 jira-2185 added /trunk/demo/ant/properties
the above uses gnu awk can set rs more single character.
to understand it, add temporary intermediate "prints" variables. specific formatting of output beyond putting tab between extracted values, man awk
, see printf
.
Comments
Post a Comment