sed(上)
过滤
# sed -n '/root/'p ahao.txt
p是打印,-n只显示匹配的字符

匹配1到5行
sed -n '1,5'p test.txt
匹配5到后面的几行
sed -n '5,$'p test.txt
全部打印出来
sed -n '1,$'p test.txt
匹配不区分大小写是大写i哦
# sed -n '/root/'Ip ahao.txt

sed -n '/^1/'p test.txt
sed -n 'in$'p test.txt
sed -n '/r..o/'p test.txt
sed -n 'oo*'p test.txt
打印第一行,然后在匹配bus
sed -e '1'p -e '/bus/'p -n test.txt
sed(下)
指定删除哪几行 (指定删除1到22行),源文件不会动,只会在当前屏幕打印出来
# sed '1,22'd ahao.txt

删除指定行并且更改文件
# sed -i '1,22'd ahao.txt

指定相关关键字行删除
# sed -i '/ahao1/'d ahao.txt
替换关键字
其中s为替换1,10为一个范围,g为全局替换,/root/TOoR /root为替换前,后面那个为替换后
# sed '1,10s/root/TOoR/g' ahao.txt

调换位置
sed -r 's/(rot)(.*)(bash)/\3\2\1/' test.txt
如果sed要替换大小写字符的话要怎么操作呢?http://ask.apelearn.com/question/7758

