unix命令svn log只获取文件信息

时间:2013-06-19 22:21:22

标签: svn unix awk cut

只需要svn log

中的目录名称和文件更改信息

这是我的svn日志

svn log -v http://test/svn/Demo/branches/HelloWorld/Batch/ --limit 2

------------------------------------------------------------------------
r133 | testuser1 | 2013-04-02 18:22:28 -0400 (Tue, 02 Apr 2013) | 3 lines
Changed paths:
M /branches/HelloWorld/Batch/test.java

DEMO-13
Testing to lock 

------------------------------------------------------------------------
r132 | testuser2 | 2013-04-02 18:20:40 -0400 (Tue, 02 Apr 2013) | 3 lines
Changed paths:
M /branches/HelloWorld/Batch/test.java

DEMO-1
Testing to lock

期望的输出:

Batch/test.java
Batch/test.java

我的剧本:

 svn log -v http://test/svn/Demo/branches/HelloWorld/Batch/ --limit 2 | awk '$1~/^[AMD]$/{for(i=2;i<=NF;i++)print $i}'

脚本输出:

/branches/HelloWorld/Batch/test.java
/branches/HelloWorld/Batch/test.java

2 个答案:

答案 0 :(得分:1)

怎么样:

what ever process you are running | awk -v FS="[/ ]" '$1~/^[AMD]$/{print $(NF-1)"/"$NF}'

测试:

[jaypal:~/Temp] cat svn.log
svn log -v http://test/svn/Demo/branches/HelloWorld/Batch/ --limit 2

------------------------------------------------------------------------
r133 | testuser1 | 2013-04-02 18:22:28 -0400 (Tue, 02 Apr 2013) | 3 lines
Changed paths:
M /branches/HelloWorld/Batch/test.java

DEMO-13
Testing to lock

------------------------------------------------------------------------
r132 | testuser2 | 2013-04-02 18:20:40 -0400 (Tue, 02 Apr 2013) | 3 lines
Changed paths:
M /branches/HelloWorld/Batch/test.java

DEMO-1
Testing to lock
[jaypal:~/Temp] awk -v FS="[/ ]" '$1~/^[AMD]$/{print $(NF-1)"/"$NF}' svn.log
Batch/test.java
Batch/test.java

答案 1 :(得分:1)

你几乎只是将字段分隔符设置为空格或正斜杠,并在匹配的行上打印最后两个字段:

awk '$1~/^[AMD]$/{print $(NF-1),$NF}' FS=' |/' OFS='/'

输出将是:

Batch/test.java
Batch/test.java