Bash 如何使用c\,使用sed设置新行?

Bash 如何使用c\,使用sed设置新行?,bash,sed,newline,busybox,Bash,Sed,Newline,Busybox,我觉得自己很愚蠢,但我尝试了多种方法在我的剧本中加入新词。我从乔纳森那里得到了sed命令的帮助。它工作得很好,但是格式丢失了,现在我找不到一种方法使它工作 代码如下所示: su -c "sed -i '/aStyle.Landscape {/,/}/c\ MImAbstractKeyAreaStyle.Landscape {\ /*** Label Setttings ***/\ label-margin-t

我觉得自己很愚蠢,但我尝试了多种方法在我的剧本中加入新词。我从乔纳森那里得到了sed命令的帮助。它工作得很好,但是格式丢失了,现在我找不到一种方法使它工作

代码如下所示:

su -c "sed -i '/aStyle.Landscape {/,/}/c\
            MImAbstractKeyAreaStyle.Landscape {\
                /*** Label Setttings ***/\
                label-margin-top: 10.6mm; /* 0.6 */\
                label-margin-left-with-secondary: -1; /* not used, labels are centered horizontally */\
                secondary-label-separation: 0;\
...
                /*** Key Area Geometry ***/\
                size: 854 -1;\
            }' file.css"

我想用另一段来代替一段。但使用此命令,所有内容都打印在一行上。我希望它保持格式。我最初的问题是:

首先尝试不使用
su-c
。在您的
引号之间,转义是不同的,这使得转义更加复杂


完成后,将结果放入脚本文件并使用
su-c./script.sh
调用该文件,或者调整转义(但这永远不会好)。

首先尝试不使用
su-c
。在您的
引号之间,转义是不同的,这使得转义更加复杂


完成后,将结果放入脚本文件并使用
su-c./script.sh
调用该文件,或者调整转义(但这永远不会好)。

这可能适合您:

echo hello | sed '/.*/c\This first line is no longer "hello"\nand this is the second line\nand this the third line'
This first line is no longer "hello"
and this is the second line
and this the third line

在GNU sed中,您可以嵌入换行符
\n
,但请参阅我对您最后一个问题的修订答案(使用此处文档)以获得所见即所得的答案。

这可能适用于您:

echo hello | sed '/.*/c\This first line is no longer "hello"\nand this is the second line\nand this the third line'
This first line is no longer "hello"
and this is the second line
and this the third line

在GNU sed中,您可以嵌入换行符
\n
,但请参阅我对您最后一个问题的修订答案(使用此处文档)以获得所见即所得的答案。

非常明显。。谢谢因为这几乎适用于我所做的所有其他案例。我没意识到这会导致它。但是我做了一些引文欺骗。。现在我知道该找什么了;)太明显了。。谢谢因为这几乎适用于我所做的所有其他案例。我没意识到这会导致它。但是我做了一些引文欺骗。。现在我知道该找什么了;)谢谢我想我可以试试。不过,我会先尝试一些报价技巧。;)谢谢我想我可以试试。不过,我会先尝试一些报价技巧。;)尽可能少地使用“su”。并以非root用户的身份进行测试。尽可能少地使用“su”。并作为非root用户进行测试。