我正在尝试创建一个脚本来替换01-network-manager-all.yaml
文件中给定网络接口的参数。
该文件看起来像这样:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s3:
dhcp4: no
dhcp6: no
addresses: [195.10.10.10/24]
gateway4: 195.10.10.10
nameservers:
addresses: [1.1.1.1]
enp0s8:
dhcp4: no
dhcp6: no
addresses: [196.10.10.10/24]
gateway4: 196.10.10.10
nameservers:
addresses: [1.1.1.1]
enp0s9:
dhcp4: no
dhcp6: no
addresses: [197.10.10.10/24]
gateway4: 197.10.10.10
nameservers:
addresses: [1.1.1.1]
假设我想替换有关的行enp0s8
并让其他行保持原样。
输出看起来像这样:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s3:
dhcp4: no
dhcp6: no
addresses: [195.10.10.10/24]
gateway4: 195.10.10.10
nameservers:
addresses: [1.1.1.1]
enp0s8:
dhcp4: no
dhcp6: no
addresses: [196.250.250.125/24]
gateway4: 196.250.250.125
nameservers:
addresses: [8.8.8.8]
enp0s9:
dhcp4: no
dhcp6: no
addresses: [197.10.10.10/24]
gateway4: 197.10.10.10
nameservers:
addresses: [1.1.1.1]
在这种情况下,我正在寻找一个sed
- 或任何其他命令 - 将替换 and 之间的所有enp0s8
内容enp0s9
。
我不是一个非常有经验的 Bash 用户,任何提示将不胜感激。
我这样做的糟糕尝试
sed -e '/^ *enp0s8:/,/^ *^enp0s9:/s/$CONFIG_TO_ADD/' "/etc/netplan/01-network-manager-all.yaml"