成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

sed運用實例一——基于變量的動態(tài)替換-創(chuàng)新互聯(lián)

在工作中我需要修改兩個文件:

我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、西安ssl等。為上1000+企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的西安網(wǎng)站制作公司

文件一:/etc/vmware/networking

  1. VERSION=1,0
  2. answer VNET_1_DHCP yes
  3. answer VNET_1_DHCP_CFG_HASH 50CE8453B1072EA401BFFA704E6C01F7AE0BA67C
  4. answer VNET_1_HOSTONLY_NETMASK 255.255.255.0
  5. answer VNET_1_HOSTONLY_SUBNET 172.16.77.0
  6. answer VNET_1_VIRTUAL_ADAPTER yes
  7. answer VNET_8_DHCP yes
  8. answer VNET_8_DHCP_CFG_HASH 1DA1A936DCB3AA3313CF293A9C96D25B76AB48A2
  9. answer VNET_8_HOSTONLY_NETMASK 255.255.255.0
  10. answer VNET_8_HOSTONLY_SUBNET 192.168.43.0
  11. answer VNET_8_NAT yes
  12. answer VNET_8_VIRTUAL_ADAPTER yes

文件二:/etc/vmware/vmnet8/dhcpd/dhcpd.conf

  1. # Configuration file for ISC 2.0 vmnet-dhcpd operating on vmnet8.
  2. #
  3. # This file was automatically generated by the VMware configuration program.
  4. # See Instructions below if you want to modify it.
  5. #
  6. # We set domain-name-servers to make some DHCP clients happy
  7. # (dhclient as configured in SuSE, TurboLinux, etc.).
  8. # We also supply a domain name to make pump (Red Hat 6.x) happy.
  9. #
  10. ###### VMNET DHCP Configuration. Start of "DO NOT MODIFY SECTION" #####
  11. # Modification Instructions: This section of the configuration file contains
  12. # information generated by the configuration program. Do not modify this
  13. # section.
  14. # You are free to modify everything else. Also, this section must start
  15. # on a new line
  16. # This file will get backed up with a different name in the same directory
  17. # if this section is edited and you try to configure DHCP again.
  18. # Written at: 03/22/2013 15:49:55
  19. allow unknown-clients;
  20. default-lease-time 1800;                # default is 30 minutes
  21. max-lease-time 7200;                    # default is 2 hours
  22. subnet 192.168.43.0 netmask 255.255.255.0 {
  23.     range 192.168.43.128 192.168.43.254;
  24.     option broadcast-address 192.168.43.255;
  25.     option domain-name-servers 192.168.43.2;
  26.     option domain-name localdomain;
  27.     default-lease-time 1800;                # default is 30 minutes
  28.     max-lease-time 7200;                    # default is 2 hours
  29.     option netbios-name-servers 192.168.43.2;
  30.     option routers 192.168.43.2;
  31. }
  32. host vmnet8 {
  33.     hardware ethernet 00:50:56:C0:00:08;
  34.     fixed-address 192.168.43.1;
  35.     option domain-name-servers 0.0.0.0;
  36.     option domain-name "";
  37.     option routers 0.0.0.0;
  38. }
  39. ####### VMNET DHCP Configuration. End of "DO NOT MODIFY SECTION" #######

需求:

將兩個文件中的"192.168.43"修改為"202.16.22",不過,有時"192.168.43"會表現(xiàn)為其它的IP值,而要修改的目標(biāo)字串"202.16.22"也可能會隨著環(huán)境的改變另行設(shè)置.

基于此需求,本人編寫了如下測試腳本:

針對文件一:

  1. #!/bin/bash
  2. # $vmnat_subnet_old變量表示vmnat8原有的子網(wǎng)配置,注意只截取前三段
  3. vmnat_subnet_old=`grep "VNET_8_HOSTONLY_SUBNET" /etc/vmware/networking | sed 's/..$//' | cut -d' ' -f 3`
  4. # $vmnat_subnet_new變量表示vmnat8子網(wǎng)的目標(biāo)配置,注意只截取前三段
  5. vmnat_subnet_new='192.168.40'
  6. cp /etc/vmware/networking /etc/vmware/networking_bak0
  7. sed -i '/VNET_8_HOSTONLY_SUBNET/s/'"$vmnat_subnet_old"'/'"$vmnat_subnet_new"'/' /etc/vmware/networking
  8. grep "$vmnat_subnet_new" /etc/vmware/networking
  9. cp /etc/vmware/networking_bak0 /etc/vmware/networking

針對文件二:

  1. #!/bin/bash
  2. # $vmnat_subnet_new變量表示vmnat8子網(wǎng)的目標(biāo)配置,注意只截取前三段
  3. vmnat_subnet_new='192.168.40'
  4. # $vmnat_subnet_old變量表示vmnat8原有的子網(wǎng)配置,注意只截取前三段
  5. vmnat_subnet_old=`grep "VNET_8_HOSTONLY_SUBNET" /etc/vmware/networking | sed 's/..$//' | cut -d' ' -f 3`
  6. cat /etc/vmware/vmnet8/dhcpd/dhcpd.conf
  7. cp /etc/vmware/vmnet8/dhcpd/dhcpd.conf /etc/vmware/vmnet8/dhcpd/dhcpd.conf_bak0
  8. sed -i '/'"$vmnat_subnet_old"'/s//'"$vmnat_subnet_new"'/g' /etc/vmware/vmnet8/dhcpd/dhcpd.conf
  9. grep "$vmnat_subnet_new" /etc/vmware/vmnet8/dhcpd/dhcpd.conf
  10. cp /etc/vmware/vmnet8/dhcpd/dhcpd.conf_bak0 /etc/vmware/vmnet8/dhcpd/dhcpd.conf

優(yōu)點:

可以不用事先知道要替換的字符是(本例中:192.168.43)什么,只需要知道自己想替換為(本例中:202.16.22)什么就可以了。

 呵呵,我的工作桌面截圖。

sed運用實例一——基于變量的動態(tài)替換

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

新聞名稱:sed運用實例一——基于變量的動態(tài)替換-創(chuàng)新互聯(lián)
地址分享:http://jinyejixie.com/article32/disssc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站營銷、品牌網(wǎng)站設(shè)計、企業(yè)建站、搜索引擎優(yōu)化、云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)
博罗县| 灵川县| 尚义县| 睢宁县| 桦甸市| 平安县| 江门市| 静宁县| 大石桥市| 北海市| 肥乡县| 南通市| 万山特区| 佳木斯市| 涿鹿县| 徐水县| 长治县| 集贤县| 翼城县| 高碑店市| 巍山| 江孜县| 内乡县| 曲周县| 墨玉县| 福鼎市| 精河县| 扬中市| 绿春县| 罗田县| 密云县| 监利县| 乌鲁木齐县| 喜德县| 保定市| 潢川县| 昔阳县| 龙井市| 沁阳市| 施秉县| 盐池县|