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

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

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

瀏覽:101日期: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

相關文章:
主站蜘蛛池模板: 武清区| 封丘县| 宜兰市| 天津市| 屏边| 洛扎县| 阳朔县| 含山县| 上思县| 肥城市| 东莞市| 延川县| 灵丘县| 射洪县| 彭水| 即墨市| 镇赉县| 姚安县| 登封市| 日土县| 楚雄市| 丹棱县| 新建县| 喀什市| 衡阳县| 荆州市| 土默特左旗| 竹北市| 肇源县| 永顺县| 梁山县| 泰兴市| 宜兰市| 天等县| 东源县| 清水县| 东城区| 溧阳市| 汤阴县| 东安县| 临颍县|