簡體   English   中英

如何使用 shell 腳本變量替換一個文件中的列,並使用 awk 語句保留作為列一部分的雙引號

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM