bash – sed替换conf 2种不同的模式

我想用sed替换conf文件中的2个entr

# Set Server
/bin/sed -i 's/server: 127.0.0.1/server: xxx.xxx.xxx.xxx/' /etc/cobbler/settings

# Set next Server
/bin/sed -i 's/next_server: 127.0.0.1/next_server: 192.168.122.1/' /etc/cobbler/settings

由于某种原因,它改变了两者的主要条目,为什么?我使用2种不同的模式来检查“服务器”& “next_server”

我也想知道如何改变引用的字符串模式

#change default password    
/bin/sed -i 's/default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."/default_password_crypted: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/' /etc/cobbler/settings

谢谢

最佳答案 只需在正则表达式的开头添加^即可要求该行以该字符串开头.

# Set Server
/bin/sed -i 's/^server: 127.0.0.1/server: xxx.xxx.xxx.xxx/' /etc/cobbler/settings

# Set next Server
/bin/sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.122.1/' /etc/cobbler/settings
点赞