【发布时间】:2014-07-19 09:17:02
【问题描述】:
我有一个 txt 文件,其中包含:
Some random
text here. This file
has multiple lines. Should be one line.
我用:
sed '{:q;N;s/\n/:sl:/g;t q}' file1.txt > singleline.txt
然后得到:
Some random:sl:text here. This file:sl:has multiple lines. Should be one line.
现在我想用newline (\n) 字符替换:sl: 模式。当我使用时:
sed 's/:sl:/&\n/g' singleline.txt
我明白了:
Some random:sl:
text here. This file:sl:
has multiple lines. Should be one line.
如何用换行符替换模式而不是在模式后添加换行符?
【问题讨论】:
-
:sl:模式是什么意思? -
sed 's/:sl:/\n/g' singleline.txt -
@AvinashRaj
:sl:表示“单行”。也可以是其他任何东西。
标签: unix text replace sed newline