sed - stream editor for ltering and transforming text
SYNOPSIS
sed [OPTION]... {script-only-if-no-other-script} [input-le]...
DESCRIPTION
-n, --quiet, --silent 不输出模式空间中内容
suppress automa%c prin%ng of pa&ern space
-e script, --expression=script 多点编辑模式
add the script to the commands to be executed
-f script-le, --le=script-le 从文件读取脚本,每行一个编辑命令
add the contents of script-le to the commands to be executed
-i[SUFFIX], --in-place[=SUFFIX] 直接在原文件编辑
edit les in place (makes backup if SUFFIX supplied)
-r, --regexp-extended 在脚本中使用扩展正则表达式
use extended regular expressions in the script.
地址定界:
1、空地址:对全文进行处理;
2、单地址:
#:指定行;
/pa&ern/:被此模式所匹配到的每一行;
3、地址范围
#,#:
#,+#:
#,/pat1/
/pat1/,/pat2/
$:最后一行;
4、步进:~
1~2:所有奇数行
2~2:所有偶数行
编辑命令
d Delete pa&ern space. Start next cycle. 删除模式空间的内容
p Print the current pa&ern space. 显示模式空间中的内容
= Print the current line number. 打印行号
a ext:在行后面追加文本“text”,支持使用 实现多行追加; (add)
i ext:在行前面插入文本“text”,支持使用 实现多行插入; (inster)
c ext:把匹配到的 行 替换为此处指定的文本“text”;
r lename Append text read from lename.
读取指定文件的内容至当前文件被模式匹配到的行后面(文件合并)
w lename Write the current paern space to lename.
保存模式空间中的内容至 lename
!:条件取反,放在模式后面,命令前面
地址定界!编辑命令;(用法)
s/regexp/replacement/ 查找替换,分隔符可自行指定,常用的有 s@@@, s###等
替换标记:
g:全局替换;
w /PATH/TO/SOMEFILE:将替换成功的结果保存至指定文件中;
p:显示替换成功的行;
[root@lxk test]# cat -n fstab #试验用文档
评论0
最新资源