【发布时间】:2014-05-19 11:18:43
【问题描述】:
我正在编写一个脚本来使用当前动态地址更新主机文件。我从 ifconfig 获取地址并使用 sed 更新 /etc/hosts。
#following returns the current VPN address e.g. 10.8.0.14
ifconfig | grep -oP 'inet addr:\K(.*)?(?= P-t-P)'
#following can be used to replace the original one with the VPN address
sudo sed -i 's/127.0.1.1/{new address}/g' /etc/hosts
但是如何将 grep 的输出通过管道传输到 sed 中的替换文本 {new address} 中?是否可以在一行中执行此操作?
【问题讨论】: