0

我感到很愚蠢,但尝试了多种方法在我的脚本中添加新行。我从 Jonathan 那里得到了一个 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"

我想用另一段替换一段。但是使用此命令,所有内容都打印在一行上。我希望它保持格式。我最初的问题在这里:如何替换文件中的段落?

4

2 回答 2

3

首先尝试不使用su -c. 在您的""报价之间,转义是不同的,并且使它变得更加复杂。

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

于 2011-12-10T12:25:09.200 回答
0

这可能对您有用:

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,但请查看我对您最后一个问题的修正答案(使用此处的文档)以获得所见即所得的答案。

于 2011-12-10T13:09:46.773 回答