当前位置: 技术问答>linux和unix
怎样用sed命令修改、删除、增加配置文件
来源: 互联网 发布时间:2017-01-02
本文导语: # 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 # th...
# 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这条数据给删除??
|
用命令将clientPortAddress=172.17.81.110里面的IP地址修改为指定IP地址
#server.3=172.17.81.113:2888:3888追加一条相同的数据,只是IP地址和前面的数据不同
需求明确一点,sed是可以解决的.
还有就是如何将#server.2=172.17.81.111:2888:3888这条数据给删除??
[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是可以解决的.
[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这条数据给删除??
cat sed2009年 | sed -r "s/^#server.2.*//g"