简体   繁体   English

sed转义单引号内的双引号

[英]sed escape double quotes within single quotes

I'm trying to add a log format to nginx.conf inside a Docker container via sed. 我正在尝试通过sed将日志格式添加到Docker容器内的nginx.conf中。 I'm issuing the following command: 我正在发出以下命令:

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

However it is giving me the following error: 但是,这给了我以下错误:

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

How can I escape the log_format command? 如何转义log_format命令?

Just use awk: 只需使用awk:

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

If you edit your question to show some sample input and expected output we can show you exactly how to replace some text with your real text. 如果您编辑问题以显示一些示例输入和预期输出,我们可以确切地向您展示如何用真实文本替换some text文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM