![다음 코드 블록을 어떻게 주석 처리할 수 있나요? [폐쇄]](https://linux55.com/image/141996/%EB%8B%A4%EC%9D%8C%20%EC%BD%94%EB%93%9C%20%EB%B8%94%EB%A1%9D%EC%9D%84%20%EC%96%B4%EB%96%BB%EA%B2%8C%20%EC%A3%BC%EC%84%9D%20%EC%B2%98%EB%A6%AC%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%82%98%EC%9A%94%3F%20%5B%ED%8F%90%EC%87%84%5D.png)
내가 가진 것:
...
{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}
때까지 패턴 공간으로 라인을 수집합니다 (단, mosvy의 주의 사항 참조). {/call}
그런 다음 대상 패턴이 패턴 공간에 있으면 줄의 /**
시작과 끝 부분에 추가합니다.*/