我想从SVN日志中提取行之间的所有文本。如果是sed,awk或grep那就更好了。
示例: svn.log
------------------------------------------------------------------------
r1075 | popad | 2011-12-02 14:28:20 +0200 (Fri, 02 Dec 2011) | 1 line
Changed paths:
M /trunk/apps/frontend/modules/mail/templates/candidateSearchAgentSuccess.php
M /trunk/apps/test.php
Ticket #1000: removing ads from emails
------------------------------------------------------------------------
r1074 | coman | 2011-11-30 10:51:29 +0200 (Wed, 30 Nov 2011) | 3 lines
Changed paths:
M /trunk/apps/frontend/i18n/messages.de.xml
M /trunk/apps/frontend/i18n/messages.en.xml
M /trunk/apps/frontend/i18n/messages.ro.xml
Ticket #1089: translation update: send to friend form
http://example.com/projects/147/tickets/1089
Solved HU translation update
------------------------------------------------------------------------
我想搜索 Ticket#1000 并检索行之间的整个块
------------------------------------------------------------------------
r1075 | popad | 2011-12-02 14:28:20 +0200 (Fri, 02 Dec 2011) | 1 line
Changed paths:
M /trunk/apps/frontend/saSuccess.php
M /trunk/apps/frontend/saAddSuccess.php
Ticket #1000: removing ads from emails
------------------------------------------------------------------------
提前致谢。
答案 0 :(得分:3)
这个awk oneliner为您提供所需的输出:
awk -vRS='-+\n' '/Ticket #1000/' svn.log
<强>测试强>
kent$ awk -vRS='-+\n' '/Ticket #1000/' svn.log
r1075 | popad | 2011-12-02 14:28:20 +0200 (Fri, 02 Dec 2011) | 1 line
Changed paths:
M /trunk/apps/frontend/modules/mail/templates/candidateSearchAgentSuccess.php
M /trunk/apps/test.php
Ticket #1000: removing ads from emails
您已经看到行分隔符(-----)未输出。如果你真的需要它可以很容易地添加。
答案 1 :(得分:2)
我建议使用svn log的xml输出,并从xml文件中提取信息,而不是......可能更简单......
svn log --xml ...
答案 2 :(得分:1)
有趣的运动,所以我去了!
% awk '
{
lines = lines "\n" $0
}
/Ticket #1000/ {
found = 1
}
/^-+$/ {
if (found) {
print lines
}
lines = $0
found = 0
}
' svn.log
------------------------------------------------------------------------
r1075 | popad | 2011-12-02 14:28:20 +0200 (Fri, 02 Dec 2011) | 1 line
Changed paths:
M /trunk/apps/frontend/modules/mail/templates/candidateSearchAgentSuccess.php
M /trunk/apps/test.php
Ticket #1000: removing ads from emails
------------------------------------------------------------------------
我认为这是不言自明的,但如果不是,我会更新答案。
即使多个提交包含搜索字符串,这也能正常工作。
将搜索字符串变量留作练习。
使用:
进行测试% awk --version
awk version 20070501
我更喜欢避免单行。如果你喜欢那种东西,那么你需要在语句之间使用分号。
答案 3 :(得分:1)
这可能对您有用:
sed '/^-\+$/{h;:a;$d;N;/-\+$/!ba;/Ticket #1000:/p;g;ba};d' svn.log