脚本宝典收集整理的这篇文章主要介绍了linux 中 sed命令,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
-
定义: 文本编辑器-(流媒体编辑器)
-
格式
-
参数
-
-i : 即时编辑
-
-f : 指定sed匹配规则脚本文件
-
-r : 支持拓展正则
-
定位
-
数字定位
-
sed '3d' 4.txt
-
sed '2,3d' 4.txt
-
正则定位
-
数字和正则定位
-
正则正则定位
-
编辑模式(至少与-i参数配合使用)(使用见操作演示)
-
案例
-
将nginx.conf中的注释行全部去掉
-
将nginx.conf中每一行之前增加注释
-
一键修改本机的ip
-
192.168.15.100 ---> 192.168.15.101
-
172.16.1.100 ---> 172.16.1.101
-
sed -i 's#.100#.101#g' /etc/sysconfig/network-scripts/ifcfg-eth[01]
-
将/etc/passwd中的root修改成ROOT
---------
操作演示
---------
模式d 删除第几行
-e 多项编辑
参数-n 取消sed 处理后的显示
参数p
打印
参数-i
就地编辑
模式d中
删除文件中xxx内容
参数-f 匹配文件内规则
上图虚假删除验证
加-i 参数 真正删除
模式d中
虚假删除文件中含xxx的行
模式d中
真正删除含b的行
模式d中
单正则 删除(删除以xxx开头的行)
模式d中
多方式删除
a 数字与正则
b 数字与数字
c 正则与正则
编辑模式a
在某行的下一行虚假添加内容
真实添加 加-i 参数
编辑模式c
替换某行内容
编辑模式i
新增一行(在当前行的上一行)
编辑模式r
在当前文件内容添加到另一文件的某行后边
编辑模式w
某文件指定行内容覆盖写入到另一文件
编辑模式y
替换文本某行内容的某些字符
编辑模式s
虚假替换文本中所有行的第一个xxx字符串
真实替换加-i参数
编辑模式sg
替换文本中所有的a字符串为b字符串
编辑模式sgi
s///g中忽略大小写
脚本宝典总结
以上是脚本宝典为你收集整理的linux 中 sed命令全部内容,希望文章能够帮你解决linux 中 sed命令所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。