如何在 awk 语句中转义撇号?

How do I escape apostraphes within an awk statement?

我在 Mac Sierra 上使用 bash shell。如何在 awk 语句中转义撇号?我正在尝试以下

localhost:myproject davea$ awk -F\, {printf "update my_table_user set thirdparty_user_id='\''%s'\'' where thirdparty_user_id='\''%s'\'';\n", $(NF-2),$(NF-1)} /tmp/myfile.csv
-bash: NF-2: command not found
-bash: NF-1: command not found
awk: syntax error at source line 1
 context is
     >>>  <<<
awk: illegal statement at source line 1
    missing }

但如您所见,它会导致一系列错误。我的目标是从 CSV 文件中提取第二列和第三列,并从中提取 SQL 语句。

您可以使用 7 作为单引号:

awk -F, '{
printf "update my_table_user set thirdparty_user_id=7%s7 where thirdparty_user_id=7%s7;\n",
$(NF-2),$(NF-1)}' /tmp/myfile.csv