Chinaunix

标题: 请教sed 修改文件中内容问题 [打印本页]

作者: LunarBull    时间: 2010-05-26 10:05
标题: 请教sed 修改文件中内容问题
文件内容如下:
volume client
   type protocol/client
   option transport-type tcp
   option remote-host 10.10.101.94
   option remote-port 6996
   option remote-subvolume brick1
end-volume

怎么用sed写一脚本把remote-host 后面的字符串 换成别的ip;然后文件保存。
作者: where27    时间: 2010-05-26 10:11
回复 1# LunarBull


    用awk吧
  1. awk '/remote-host/{$NF="其他ip"}1' file
复制代码

作者: lkk2003rty    时间: 2010-05-26 10:11
  1. sed -i 's/\(.*remote-host\)\(.*\)/\1 IP/' file
复制代码

作者: LunarBull    时间: 2010-05-26 11:12
谢谢你们!
作者: LunarBull    时间: 2010-05-28 18:11

作者: blackold    时间: 2010-05-28 18:19

作者: kaixin9ok    时间: 2010-05-28 22:37
sed -i 是什么意思?


sed -r 's/(.*remote-host)(.*)/\1 IP/' file
作者: lkk2003rty    时间: 2010-05-28 22:49
回复 7# kaixin9ok


    直接修改原文件。。。运行指令后原文件就变成你改完的样子了。。。。。。。。
作者: kaixin9ok    时间: 2010-05-29 00:03
回复 8# lkk2003rty


哈哈...这回记住了...
      
      有点印象的..就是不记得是个啥意思...
作者: Shell_HAT    时间: 2010-05-29 00:35
回复 9# kaixin9ok


下次忘记了之后,先问问男人。
作者: aluoyeshi    时间: 2010-05-30 00:55
sed -i '/host/s/\(.*remote-host \).*/\110.10.101.1/' filename




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2