我有config.txt
,其中包含
DB_IP=10.10.1.120, DB_NAME=mysql
然后我创建了一个带有占位符的文件details.txt
,即
DB_ip_address=@@ip@@, DB_name=@@name@@
现在我需要一个临时文件,从config.txt
获取详细信息并替换details.txt
中的占位符。所以我的临时文件应该是
DB_ip_address=10.10.1.120
DB_name=mysql
答案 0 :(得分:1)
你可以试试这个:
x=($(grep -Po "(?<=DB_IP=)(.+)(?=,)|(?<=DB_NAME=)(.+)" config.txt))
y=($(grep -Eo "[a-zA-Z_]+=" details.txt))
echo $y$x > temp.txt
echo ${y[1]}${x[1]} >> temp.txt
假设两个文件中DB_IP和DB_NAME的顺序始终相同。