-
删除第2行
nl /etc/passwd|sed '2d'
-
删除第3行到最后一行
nl /etc/passwd|sed '3,$d'
-
在第2行后加上字符串drink tea
nl /etc/passwd|sed '2a drink tea'
-
在第2行前加上字符串drink tea
nl /etc/passwd|sed '2i drink tea'
-
在第2行后加入两行内容drink tea? drink beer?
nl /etc/passwd|sed '2a drink tea?回车 drink beer?'
-
将2~5行内容取代为this is line 2-5
nl /etc/passwd|sed '2,5c this is line 2-5'
-
列出第5~7行
nl /etc/passwd|sed -n '5,7p'
-
从ifconfig信息中截取出本机IP
ifconfig eth0|grep 'inet addr:'|sed 's/^.*addr://g'|sed 's/Bcast.*$//g'
-
直接替换文档内.为!
sed -i 's/./!/g' regular_expression.txt
-
删除第4行,第6行取代为no six line
cat /etc/passwd|sed -e '4d' -e '6c no six line' > passwd.new