Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用perl进行文件编辑_Perl - Fatal编程技术网

使用perl进行文件编辑

使用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

我有一个大文件(有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 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,但这种方式似乎更清晰(至少对我来说:)