http://www.gnu.org/software/sed/manual/html_node/Programming-Commands.html
Commands for sed gurus
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'
冒號開頭:后面隨便借個字母 設置個label 例如:f
b a ; 表示無條件到:a 這里繼續執行 例子 ':a;$!N;$!ba;$s/\n/g' 所有內容 一行輸出 循環作用
t a ; 表示前面的s/ / 成功比配到 了 變 跳轉到:a繼續執行 例子':a;N;s/aa\nbb/woyn/;ta;P;D'