1

我有一个文本文件,其内容如下:

Fri Oct 02 19:52:02 +0000 2009 | JeLLz Mamii;) | DopeAssDarLey | my b.i⥠BITCH!! | @_steffhoney lmfao oh Dayum gull inee hihup Walmart en boiy maself sum skoo sepplies

Tue Aug 30 23:29:47 +0000 2011 | Braydon Tyrrell | braydon_tyrrell | westlock. AB. canada | RT @Darkskin: RT @JazmineDukes: @Darkskin Who are you that U have a blue check mark by ur name?? < 
I polish shoes at Walmart while pp ...

可以看出“我擦鞋..”是第二条记录的一部分Tues Aug 30。但是在处理此文件时,它被视为第三条完全不同的记录。

我希望能够将“我擦鞋”行与它之前的行合并,即“用你的名字打勾??” 有没有办法做到这一点。文件中的许多记录中都存在这种异常情况。所以我需要能够为所有此类记录执行此操作,以便我的输出看起来像

Fri Oct 02 19:52:02 +0000 2009 | JeLLz Mamii;) | DopeAssDarLey | my b.i⥠BITCH!! | @_steffhoney lmfao oh Dayum gull inee hihup Walmart en boiy maself sum skoo sepplies

Tue Aug 30 23:29:47 +0000 2011 | Braydon Tyrrell | braydon_tyrrell | westlock. AB. canada | RT @Darkskin: RT @JazmineDukes: @Darkskin Who are you that U have a blue check mark by ur name?? < I polish shoes at Walmart while pp ...
4

3 回答 3

1

如果它包含尾随空格,这将加入下一行:

sed '/ $/ N; s/\n//' file.txt

但是,如果可能有多行带有尾随空格,则需要一个循环:

sed -e :a -e '/ $/ { $!N; s/\n//; ta }' file

结果:

Fri Oct 02 19:52:02 +0000 2009 | JeLLz Mamii;) | DopeAssDarLey | my b.i⥠BITCH!! | @_steffhoney lmfao oh Dayum gull inee hihup Walmart en boiy maself sum skoo sepplies

Tue Aug 30 23:29:47 +0000 2011 | Braydon Tyrrell | braydon_tyrrell | westlock. AB. canada | RT @Darkskin: RT @JazmineDukes: @Darkskin Who are you that U have a blue check mark by ur name?? < I polish shoes at Walmart while pp ...
于 2012-10-31T11:37:51.553 回答
0

你可以试试:

awk -v RS='\n\n+' '{ sub(/\n/, "", $0) ; print $0 "\n" }' log.txt
于 2012-10-31T11:37:13.177 回答
0
perl -00 -lpe 's/\n//g'

一次读取文件一个“段落”,并删除“内部”换行符。

于 2012-10-31T14:00:40.250 回答