怎样用sed命令修改、删除、增加配置文件
时间:2011-09-22
来源:互联网
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=5
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=2
# the port at which the clients will connect
clientPort=2181
maxClientCnxns=1000
dataDir=/hds/zk/zdatadir
dataLogDir=/hds/zk/zlogdir
clientPortAddress=172.17.81.110
#server.1=172.17.81.110:2888:3888
#server.2=172.17.81.111:2888:3888
#server.3=172.17.81.113:2888:3888
上面是我的一个配置文件,现在我要用命令将clientPortAddress=172.17.81.110里面的IP地址修改为指定IP地址
后面还会在#server.3=172.17.81.113:2888:3888追加一条相同的数据,只是IP地址和前面的数据不同,
还有就是如何将#server.2=172.17.81.111:2888:3888这条数据给删除??
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=5
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=2
# the port at which the clients will connect
clientPort=2181
maxClientCnxns=1000
dataDir=/hds/zk/zdatadir
dataLogDir=/hds/zk/zlogdir
clientPortAddress=172.17.81.110
#server.1=172.17.81.110:2888:3888
#server.2=172.17.81.111:2888:3888
#server.3=172.17.81.113:2888:3888
上面是我的一个配置文件,现在我要用命令将clientPortAddress=172.17.81.110里面的IP地址修改为指定IP地址
后面还会在#server.3=172.17.81.113:2888:3888追加一条相同的数据,只是IP地址和前面的数据不同,
还有就是如何将#server.2=172.17.81.111:2888:3888这条数据给删除??
作者: cqranbihong 发布时间: 2011-09-22
clientPortAddress=172.17.81.110修改IP地址已经可以了,用下面的命令
sed -i 's/\(clientPortAddress=\)\S\S*/\1102.117.2.23/' test.txt
sed -i 's/\(clientPortAddress=\)\S\S*/\1102.117.2.23/' test.txt
作者: cqranbihong 发布时间: 2011-09-22
用命令将clientPortAddress=172.17.81.110里面的IP地址修改为指定IP地址
C/C++ code
#server.3=172.17.81.113:2888:3888追加一条相同的数据,只是IP地址和前面的数据不同
需求明确一点,sed是可以解决的.
C/C++ code
还有就是如何将#server.2=172.17.81.111:2888:3888这条数据给删除??
C/C++ code
C/C++ code
[owenliang@localhost bashShell.dir]$ cat sed2009年 | sed -r "s/^(clientPortAddress=)[0-9.]*/\1102.117.2.23/g"
#server.3=172.17.81.113:2888:3888追加一条相同的数据,只是IP地址和前面的数据不同
需求明确一点,sed是可以解决的.
C/C++ code
[owenliang@localhost bashShell.dir]$ line=`wc -l sed2009年 | cut -d " " -f 1` [owenliang@localhost bashShell.dir]$ echo $line 19 [owenliang@localhost bashShell.dir]$ cat sed2009年 | sed "$line a #server.4=127.0.0.1" # The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=5 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=2 # the port at which the clients will connect clientPort=2181 maxClientCnxns=1000 dataDir=/hds/zk/zdatadir dataLogDir=/hds/zk/zlogdir clientPortAddress=172.17.81.110 #server.1=172.17.81.110:2888:3888 #server.2=172.17.81.111:2888:3888 #server.3=172.17.81.113:2888:3888 #server.4=127.0.0.1
还有就是如何将#server.2=172.17.81.111:2888:3888这条数据给删除??
C/C++ code
cat sed2009年 | sed -r "s/^#server.2.*//g"
作者: qq120848369 发布时间: 2011-09-22
[owenliang@localhost bashShell.dir]$ cat sed2009年 | sed "$ a #server.4=127.0.0.1"
这个就行了... 我记起来有个$表示最后一行.
这个就行了... 我记起来有个$表示最后一行.
作者: qq120848369 发布时间: 2011-09-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28