久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

linux - 寫一個修改文件中配置信息的腳本,執行錯誤

瀏覽:96日期:2024-06-12 18:28:21

問題描述

主要有三個文件 test.cnf test.sh test.txt執行test.sh去讀取test.cnf的配置來修改test.txt的內容,執行過程中讀取配置成功但sed執行的時候沒找到。sed這里只是調試沒去修改test.txt,只是顯示test.txt的結果

[root@localhost /tmp]# head -100 test*==> test.cnf <==yy=123ppp=456==> test.sh <==function myconf(){source test.cnfawk -F’=’ ’{print $1}’ test.cnf|while read myline;do sed s/{{$myline}}/${$myline}/g test.txt;done}myconf==> test.txt <==uuu={{yy}}ooo={{ppp}}

調試的時候就顯示執行錯誤;

[root@localhost /tmp]# bash -x test.sh+ myconf+ source test.cnf++ yy=123++ ppp=456+ read myline+ awk -F= ’{print $1}’ test.cnftest.sh: line 4: s/{{$myline}}/${$myline}/g: bad substitution

問題解答

回答1:

while read a b;do sed -n 's/$a/$b/p' test.txt;done < <(awk -F= ’{print $1,$2}’ test.cnf)

linux - 寫一個修改文件中配置信息的腳本,執行錯誤

其它方法:

awk -F= -vOFS=’=’ ’NR==FNR{a[$1]=$2;next}{for(i in a)if($2 ~ i)sub(i,a[i],$2)}1’ test.cnf test.txt

相關文章:
主站蜘蛛池模板: 商城县| 胶州市| 通道| 石柱| 额敏县| 汪清县| 壶关县| 浙江省| 松阳县| 青田县| 延庆县| 涡阳县| 合江县| 普兰店市| 泉州市| 洱源县| 来宾市| 北安市| 龙川县| 龙门县| 赤水市| 黄山市| 大悟县| 秦皇岛市| 宝应县| 石景山区| 理塘县| 金乡县| 东宁县| 石渠县| 岢岚县| 湖口县| 阳春市| 巫山县| 汉寿县| 绥宁县| 疏勒县| 新昌县| 定襄县| 武义县| 赫章县|