Posted on 2010-01-19 17:00
Prayer 阅读(391)
评论(0) 编辑 收藏 引用 所属分类:
Shell
http://www.gnu.org/software/sed/manual/html_node/Programming-Commands.html Commands for
sed gurus
In most cases, use of these commands indicates that you are probably better off programming in something like awk or Perl. But occasionally one is committed to sticking with sed, and these commands can enable one to write quite convoluted scripts.
:
label
- [No addresses allowed.]
Specify the location of label for branch commands. In all other respects, a no-op.
b
label
- Unconditionally branch to label. The label may be omitted, in which case the next cycle is started.
t
label
- Branch to label only if there has been a successful
s
ubstitution since the last input line was read or conditional branch was taken. The label may be omitted, in which case the next cycle is started.
主要 和 t ; b 命令联合使用
冒号开头:后面随便借个字母 设置个label 例如:f
b a ; 表示无条件到:a 这里继续执行 例子 ':a;$!N;$!ba;$s/\n/g' 所有内容 一行输出 循环作用
t a ; 表示前面的s/ / 成功比配到 了 变 跳转到:a继续执行 例子':a;N;s/aa\nbb/woyn/;ta;P;D'