【发布时间】:2014-10-05 20:26:21
【问题描述】:
我有一个看起来像这样的文件
line one
line two
line three
line four
我希望它看起来像这样(我希望将第 2 行和第 3 行合并为一个)
line one
line two line three
line four
我尝试了以下方法,根据我的研究应该做我想做的事:
$ sed '2s/\n/ /' test.txt > test2.txt
然而test2.txt 看起来像这样
line one
line two
line three
line four
我已经看到一些关于它在 Solaris 上与 Linux 上不同的引用。这是我的服务器的详细信息
$ uname -a
SunOS myserver 5.10 Generic_142909-17 sun4u sparc SUNW,Sun-Fire-V490
我怎样才能让它得到我想要的结果?
【问题讨论】:
-
请参阅this question,它解释了为什么使用 sed 有点困难。
-
您要将第二行与第三行合并,还是将
line two与line three合并,无论它们在文件中的位置如何? -
它是基于行号,而不是行的值