【问题标题】:sed escape double quotes within single quotessed 在单引号内转义双引号
【发布时间】:2015-11-06 07:54:36
【问题描述】:

我正在尝试通过 sed 在 Docker 容器内的 nginx.conf 中添加日志格式。我发出以下命令:

sed -i -e"s/client_max_body_size 100M/client_max_body_size 100M;\n\tlog_format specialLog '$remote_addr forwarded for $http_x_real_ip - $remote_user [$time_local]  '
                                                                                                  '"$request" $status $body_bytes_sent '
                                                                                                  '"$http_referer" "$http_user_agent"'/" /etc/nginx/nginx.conf

但是它给了我以下错误:

sed: -e expression #1, char 105: unterminated `s' command

如何转义 log_format 命令?

【问题讨论】:

标签: regex bash nginx sed


【解决方案1】:

只需使用 awk:

awk '1; /client_max_body_size 100M/{ print "some text" }' file

如果您编辑问题以显示一些示例输入和预期输出,我们可以准确地向您展示如何将 some text 替换为您的真实文本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 2013-06-17
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 2011-04-19
    相关资源
    最近更新 更多