sed - what is this curly brace notation called?

强颜欢笑 提交于 2020-04-05 15:34:09

问题


I just found this:

sed '/label/{n;n;s/{}/{some comment}/;}'

The intended effect is to seek label, proceed 2 lines down (n;n;) then substitute in (s) some comment.

This is an amazing capability I never knew sed had.

Would someone be kind enough to specify the name of this curly brace notation, and the name of the class of operators inside the braces?


回答1:


Curly brackets allow to group several commands so that they are executed for the same address range (reference). The thing here is that you specify an address (with one or two line numbers or patterns) and then apply a group of commands to matching lines.

The n command is nothing special, and it's documented in man, as well as in the linked document. I'm not sure if there's a general name for it.

From man sed:

n N Read/append the next line of input into the pattern space.



来源:https://stackoverflow.com/questions/12497489/sed-what-is-this-curly-brace-notation-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!