当前位置: > shell编程 >

sed删除文件中的一行

时间:2014-09-15 02:55来源:linux.it.net.cn 作者:it

先来看下原始文件的内容:
 

复制代码代码如下:
root@localhost ~]# cat file.txt
hello world
a:b:c -h -n
a:b:c -h -n

sed根据条件删除相关的行:
 

复制代码代码如下:
[root@localhost ~]# sed -i '/a:b:c -h -n/d' file.txt
[root@localhost ~]# cat file.txt
hello world

sed根据条件进行相关内容的替换:
 

复制代码代码如下:
[root@localhost ~]# sed -i 's/hello/baidu/' file.sh
[root@localhost ~]# cat file.sh
baidu world
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容