使用perl进行文件编辑
我有一个大文件(有20000多行),其中一些行以“+”开头。其形式如下:使用perl进行文件编辑,perl,Perl,我有一个大文件(有20000多行),其中一些行以“+”开头。其形式如下: 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 li
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实现这一点?就地文件编辑
perl -i -pe 'BEGIN{ $/ ="\n+" } chomp' file
很好的解决方案。也许可以考虑:
BEGIN{$/.=“+”}
@Miller,但这种方式似乎更清晰(至少对我来说:)