国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

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

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

相關文章:
主站蜘蛛池模板: 油尖旺区| 丹棱县| 柳州市| 贺州市| 温州市| 马山县| 米泉市| 霍州市| 昭觉县| 新干县| 云梦县| 万安县| 普陀区| 正定县| 观塘区| 平南县| 沅陵县| 根河市| 五家渠市| 昭苏县| 东阳市| 华池县| 奉贤区| 北安市| 长丰县| 建瓯市| 江永县| 响水县| 张家口市| 娄底市| 巨鹿县| 体育| 张家口市| 安顺市| 萍乡市| 遵义市| 肃宁县| 平昌县| 平定县| 嵊州市| 夏邑县|