使用perl进行文件编辑

时间:2014-09-25 19:46:07

标签: perl

我有一个大文件(超过20,000行),其中一些行正在盯着" +"。它的形式为:

This is a file with many lines
Some lines start with plus
+ line one
+ line two
Some lines do
not start with plus
+ line three
+ line four

我想加入所有以+开头的行与前一行。所以我的输出应该如下:

This is a file with many lines
Some lines start with plus line one line two
Some lines do
not start with plus line three line four

如何使用perl执行此操作?

1 个答案:

答案 0 :(得分:1)

就地文件编辑,

perl -i -pe 'BEGIN{ $/ ="\n+" } chomp' file