打印操作:n命令
所有行打印,第二行打印两遍 sed '2p' passwd
只打印第二行sed -n '2p' passwd
打印1~3行 sed -n '1,3p' passwd
打印带有'root'的行 sed -n '/root/p' passwd
打印包含'root'行到第8行(第10行包含root时也会打印) sed -n '/shutdown/,8p' passwd
打印包含'shutdown'行到包含'root'的行 sed -n '/shutdown/,/'root'/p' passwd
打印非空格行 sed -n '/^$/!p' testfile
替换操作:s命令
从第二个替换:echo 'aaaaaaAAA'|sed 's/a/N/2g' :aNNNNNAAA:
删除命令 -d
删除空白行:sed /^$/d testfile
删除第一行:sed '1d' testfile
删除文件的第2行到末尾所有行:sed '2,$d' testfile
删除最后一行:sed '$d' testfile
组合多个表达式
sed '表达式' | sed '表达式'