Basic
Syntax
- -i edit file
- -f run script from file, e.g: sed -f script-file test.txt
- -n only print the match line
command
- N, add the next line to current buffer for operation
- a, append, using for add line
- i, insert, using for add line
- d, delete, using for delete line
- p, print
: b t
, flow control, “:
“ is a label, “b
“ means branch and “t
“ is test- H,h,G,g,x: put patter space content to storage space
regular express
- ^ 表示一行的开头。如:/^#/ 以#开头的匹配。
- $ 表示一行的结尾。如:/}$/ 以}结尾的匹配。
- \< 表示词首。 如 \<abc 表示以 abc 为首的詞。
- > 表示词尾。 如 abc> 表示以 abc 結尾的詞。
- . 表示任何单个字符。
- 表示某个字符出现了0次或多次。
- [ ] 字符集合。 如:[abc]表示匹配a或b或c,还有[a-zA-Z]表示匹配所有的26个字符。如果其中有^表示反,如[^a]表示非a的字符
Skills
sed [options] 'command' file(s)
sed [options] -f scriptfile file(s)
sed -i '/'$prj'/{s/\(.*#.*#\)[0-9]\+/\1'$rev_new'/}' $conf_file
, replace revision with new revisionsed -n 10,23p filepath
, -n print the specific linessed 'N;s/\n/ /' filepath
, join two line into oneecho -e "11\n22\n33\n" | sed -n '/22/{n;p}'
, print next line after matchsed ':a;N;s/\n/ /;ba;' file
, join all lines (set labela
, put the next to
operate buffer, substitute\n
to space symbol, goto lablea
, job continue.
sample
delete tags from html, using
sed 's/<[^>]*//g' test.html
This is what I meant. Understand?