所以我想替换以下内容
<duration>89</duration>
与 (预期结果或者至少应该变成这样:)
\n<duration>89</duration>
所以基本上用正则表达式中的\n< 替换每个 < 所以我想。
sed -e 's/<[^/]/\n</g'
它明显输出的唯一问题
\n<uration>89</duration>
这引出了我的问题。我怎样才能告诉正则表达式匹配<(不是/)后面的字符,但阻止它替换它,以便我可以获得预期的结果?
最佳答案
试试这个:
sed -e 's/<[^/]/\\n&/g' file
或
sed -e 's/<[^/]/\n&/g' file
&
: refer to that portion of the pattern space which matched
关于正则表达式模式替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37908292/