首页 > 其他 > 详细

sed

时间:2015-09-25 11:23:35      阅读:237      评论:0      收藏:0      [点我收藏+]

a 追加内容 sed ‘/匹配词/a\要加入的内容’ example.file(将内容追加到匹配的目标行的下一行位置)
i 插入内容 sed ‘/匹配词/i\要加入的内容’ example.file 将内容插入到匹配的行目标的上一行位置)
示例:
#我要把文件的包含“chengyongxu.com”这个关键词的行前或行后加入一行,内容为“allow chengyongxu.cn”


#行前加

sed -i ‘/allow chengyongxu.com/i\allow chengyongxu.cn‘ the.conf.file

#行前后

sed -i ‘/allow chengyongxu.com/a\allow chengyongxu.cn‘ the.conf.file



1、删除指定行的上一行
sed -i -e :a -e ‘$!N;s/.*\n\(.*ServerName abc.com\)/\1/;ta‘ -e ‘P;D‘ $file
2、删除指定字符串之间的内容
sed -i ‘/ServerName abc.com/,/\/VirtualHost/d‘ $filehttp://www.linuxso.com/shell/17542.html


搜索‘REJECT‘内容,在此行最前面加注释

sed -i ‘/REJECT/s/^/#/‘ /etc/sysconfig/iptables

本文出自 “智能化未来_XFICC” 博客,请务必保留此出处http://xficc.blog.51cto.com/1189288/1698099

sed

原文:http://xficc.blog.51cto.com/1189288/1698099

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!