Skip to main content

sed

caution
  • sed 一次只能操作一行
commandstand for
:label
=line_number
aappend_text_to_stdout_after_flush
bbranch_unconditional
crange_change
dpattern_delete_top/cycle
Dpattern_ltrunc(line+nl)_top/cycle
gpattern=hold
Gpattern+=nl+hold
hhold=pattern
Hhold+=nl+pattern
iinsert_text_to_stdout_now
lpattern_list
npattern_flush=nextline_continue
Npattern+=nl+nextline
ppattern_print
Ppattern_first_line_print
qflush_quit
rappend_file_to_stdout_after_flush
ssubstitute
tbranch_on_substitute
wappend_pattern_to_file_now
xswap_pattern_and_hold
ytransform_chars
# perl in place replace
# 可以 替换 \r\n - sed 不可以
# -i.bak 可生成备份文件
perl -ipe 's/\n//' file

替换片段

lead='^### BEGIN COMMON'
tail='^### END COMMON'
sed -e "/$lead/,/$tail/{ /$lead/{p; r stub/Makefile
}; /$tail/p; d }" commons/Makefile