我拥有的:
...
{if $dockerPipelinesEnabled}
{call aui.buttons.button}
{param text: getText('deployment.environment.docker.button') /}
{param tagName: 'a' /}
{param id: 'configureEnvironmentDocker' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentDocker.action?environmentId=' + $id ] /}
{/call}
{/if}
{call aui.buttons.button}
{param text: getText('deployment.project.environment.agents') /}
{param tagName: 'a' /}
{param id: 'configureEnvironmentAgents' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentAgents.action?environmentId=' + $id ] /}
{/call}
{call widget.override.aui.badgeButton}
{param text: getText('environment.notifications') /}
{param tagName: 'a' /}
{param id: 'configureDeploymentsNotifications' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentNotifications.action?environmentId=' + $id ] /}
{param badgeText: $notificationsNumberString /}
{/call}
...
我想要的是:
...
{if $dockerPipelinesEnabled}
{call aui.buttons.button}
{param text: getText('deployment.environment.docker.button') /}
{param tagName: 'a' /}
{param id: 'configureEnvironmentDocker' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentDocker.action?environmentId=' + $id ] /}
{/call}
{/if}
/** {call aui.buttons.button}
{param text: getText('deployment.project.environment.agents') /}
{param tagName: 'a' /}
{param id: 'configureEnvironmentAgents' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentAgents.action?environmentId=' + $id ] /}
{/call} */
{call widget.override.aui.badgeButton}
{param text: getText('environment.notifications') /}
{param tagName: 'a' /}
{param id: 'configureDeploymentsNotifications' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentNotifications.action?environmentId=' + $id ] /}
{param badgeText: $notificationsNumberString /}
{/call}
...
我可以注释多个语句中的唯一行,但是该代码块中存在其他块中存在的公共行。
可接受的格式有:
/** {call aui.buttons.button}
{param text: getText('deployment.project.environment.agents') /}
{param tagName: 'a' /}
{param id: 'configureEnvironmentAgents' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentAgents.action?environmentId=' + $id ] /}
{/call} */
或者:
/** {call aui.buttons.button} */
/** {param text: getText('deployment.project.environment.agents') /} */
/** {param tagName: 'a' /} */
/** {param id: 'configureEnvironmentAgents' + $id /} */
/** {param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentAgents.action?environmentId=' + $id ] /}
/** {/call} */
编辑
我试图用:sed
and解决这个问题awk
,但它看起来相当微不足道grep
grep --invert-match "$(grep -B 1 -A 4 .*deployment.project.environment.agents <path-to-file>
看起来并grep
没有将匹配视为一个块,而是删除了每一行,这会破坏结果。
更新
完整文件是这里(感兴趣的片段位于底部)
在该文件中,我希望注释掉上面的部分(如可接受的格式)。
请注意,{call aui.buttons.button}
出现在多个位置,因此单独作为标记是不够的。删除代码块也是可以接受的。
答案1
尝试sed
:
sed '/{call/ {:L; N; /{\/call/!bL; /deployment.project/ {s/^/\/**/; s/$/*\//}} ' file
{if $dockerPipelinesEnabled}
{call aui.buttons.button}
{param text: getText('deployment.environment.docker.button') /}
{param tagName: 'a' /}
{param id: 'configureEnvironmentDocker' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentDocker.action?environmentId=' + $id ] /}
{/call}
{/if}
/** {call aui.buttons.button}
{param text: getText('deployment.project.environment.agents') /}
{param tagName: 'a' /}
{param id: 'configureEnvironmentAgents' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentAgents.action?environmentId=' + $id ] /}
{/call}*/
{call widget.override.aui.badgeButton}
{param text: getText('environment.notifications') /}
{param tagName: 'a' /}
{param id: 'configureDeploymentsNotifications' + $id /}
{param extraAttributes: [ 'href': contextPath() + '/deploy/config/configureEnvironmentNotifications.action?environmentId=' + $id ] /}
{param badgeText: $notificationsNumberString /}
{/call}
每次遇到时,{call}
它都会将线条收集到模式空间中,直到{/call}
找到为止(不过,请参阅 mosvy 的警告)。然后,如果目标模式位于模式空间中,则/**
在行首和*/
行尾添加。