簡體   English   中英

awk output 中變量加雙引號

[英]Add double quotes to variables in awk output

對於此文件中的每一行,我根據 | 進行分隔並且需要加雙引號 Here are the contents of file

ks|active|0.1|0
ks|dc|0.1|0
ks|process|0.1|0

所需 output

ALTER TABLE "ks"."active" WITH gc_grace_seconds=0;
ALTER TABLE "ks"."dc" WITH gc_grace_seconds=0;
ALTER TABLE "ks"."process" WITH gc_grace_seconds=0;

這是我正在使用的命令(它沒有將值附加到 $1 和 $2

cat table_list | awk -F '|' {'print "ALTER TABLE " $1 "." $2 " WITH gc_grace_seconds=0;" '}

output 來自我正在使用的命令

ALTER TABLE ks.active WITH gc_grace_seconds=0;
ALTER TABLE ks.dc WITH gc_grace_seconds=0;
ALTER TABLE ks.process WITH gc_grace_seconds=0;

你不需要cat ,你可以使用printf這可能更容易獲得所需的 output

awk -F\| '{printf("ALTER TABLE \"%s\".\"\%s\" WITH gc_grace_seconds=0;\n", $1, $2)}' < table_list

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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