[英]How to Replace a column in one file with shell script variable and keep the Double quotes that are part of the column with an awk statement
文件中的行:
where so.name ="tblname"
shell 腳本變量設置為:
for tablename in `cat $TBLNAME.$DBNAM.out`
shell 腳本中的awk
語句:
awk -v xy="$tablename" '$1=="where"{$4='\"xy\"'}1' $COLMNAME > tmp2 && mv tmp2 $COLMNAME
執行 awk 語句后輸出文件中的行:
where so.name = xy
我想要的是:
where so.name = "tbuser"
你必須在那里轉義雙引號(不使用單引號)。
awk -v xy="$tablename" '$1=="where"{$4="\""xy"\""}1' file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.