脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - shell - sed删除文件中的一行内容的脚本代码

sed删除文件中的一行内容的脚本代码

2022-12-19 15:53脚本之家 shell

sed删除文件中的一行内容的脚本代码,需要的朋友可以参考下

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

复制代码 代码如下:


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

延伸 · 阅读

精彩推荐