Posted on 2010-01-19 17:00
Prayer 閱讀(421)
評(píng)論(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 命令聯(lián)合使用
冒號(hào)開頭:后面隨便借個(gè)字母 設(shè)置個(gè)label 例如:f
b a ; 表示無條件到:a 這里繼續(xù)執(zhí)行 例子 ':a;$!N;$!ba;$s/\n/g' 所有內(nèi)容 一行輸出 循環(huán)作用
t a ; 表示前面的s/ / 成功比配到 了 變 跳轉(zhuǎn)到:a繼續(xù)執(zhí)行 例子':a;N;s/aa\nbb/woyn/;ta;P;D'