linux 三剑客之------sed

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34646546/article/details/88812448

linux 三剑客之------sed

执行过程

参数

参数 作用
-n 取消默认出输出
-i

加-i后会实际修改文件内容

-r 支持正则

使用方法

sed -n '3p' yuming.txt  输出文件的第三行

sed -n '1,3p' yuming.txt 输出文件的一到三行

sed '/www/p' yuming.txt 输出文件包含www的行

sed '/www/d' yuming.txt 删除文件包含www的行

sed  -n '/{/,/}/p'  range.log 输出文件中{到}的内容

sed 's#www#blog#g'  range.log 全局替换  ,把文件中的www替换为blog

后向引用:

[root@alice tmp]# cat yuming.txt
this is a example
[root@alice tmp]# sed -r 's#(.*)#\1 for 后向引用#g' yuming.txt 
this is a example for 后向引用

猜你喜欢

转载自blog.csdn.net/qq_34646546/article/details/88812448