2015-08-13 102 views
0

我想通过sed将日志格式添加到Docker容器内的nginx.conf中。我发出以下命令:单引号内的sed转义双引号

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命令?

+1

试试这个http://stackoverflow.com/a/206963/4258817 – Mousey

+0

我复制/经过你的命令,它对我来说工作正常。你的变量值是什么? – hogren

+0

请参阅:https://unix.stackexchange.com/questions/168862/why-does-sed-outputs-char-53-unterminated-s-command您的命令是否有换行符?这可能是错误的。 –

回答

0

只需使用AWK:

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

如果您编辑您的问题表现出一些样品的输入和预期的输出,我们可以告诉你究竟是如何与真实的文本替换some text