【问题标题】:awk escape single quote [duplicate]awk转义单引号[重复]
【发布时间】:2020-12-27 16:07:34
【问题描述】:

假设如下:

head delete.txt | awk '{printf("curl -XPOST 'localhost:52000/buildings/_search?pretty' -H 'Content-Type: application/json' -d' { '\'"query'\'": { '\'"match'\'": { '\'"building.id'\'" : '\'"%s'\'"} } } '; \n", $1);}'

其中包含一些字符串,并且双引号已转义(“)以便打印。单引号呢?

错误信息是 awk: ^ unterminated string

【问题讨论】:

  • 多么奇怪的命令行。我会使用xargs printf

标签: ubuntu awk


【解决方案1】:

单引号呢?

我看到它通常被用作变量。

awk -v q="'" 'BEGIN {print q "Something" q}' </dev/null

但在你的情况下,我会放弃 awk 并且如果你打算执行 curl:

head delete.txt | xargs -d '\n' -I {} curl -XPOST 'localhost:52000/buildings/_search?pretty' -H 'Content-Type: application/json' -d '{ "query": { "match": { "building.id" :  "{}" }}'

或与printf 类似,仅用于格式化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-17
    • 2012-04-11
    • 2021-10-09
    • 2012-12-27
    • 2012-05-28
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多