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

时间:2011-12-10 11:18:21

标签: bash sed newline busybox

我感觉很愚蠢,但我尝试了多种方法在我的脚本中使用新行。我从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"

我想用另一个段落替换一个段落。但是使用此命令,所有内容都打印在一行上。我希望它保持格式化。我原来的问题是:How to substitute a paragraph in file?

2 个答案:

答案 0 :(得分:3)

首先尝试不使用su -c。在你的""引号之间,转义是不同的,并使其更加复杂。

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

答案 1 :(得分: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,但请查看我对您的最后一个问题(使用here-document)的修正回答,以获取WYSIWYG答案。