-1

我有一个大文件,我想从使用 Perl 中删除多行,所以不能选择啜饮。

它的香料文件是这样的:

X1 param param param
+param param param
+param param param
X2 param param param
+param param param
+param param param
+param param param
X3 param param param
+**target_param** param param param
+param param param
+param param param
X4 param **target_param** param param
+param param param
+param param param

目标可以是任何地方,任何实例,即任何以 X(N) 到但不包括 X(N+1) 的行都需要从输出文件中省略。

样本输出:

X1 param param param
+param param param
+param param param
X2 param param param
+param param param
+param param param
+param param param
4

1 回答 1

1

这可能是一个解决方案吗?它不包括第二次出现的target_parameter.

更新:解决方案现在只是在“块”中寻找target_parameter,而不是在连续的块中(正如我首先理解的问题)。

#!/usr/bin/perl
use strict;
use warnings;

{
    local $/ = 'X';
    <DATA>; # discard first block (empty)
    while (<DATA>) {
        chomp;
        print "X$_" unless /target_param/;
    }   
}
__DATA__
X1 param param param
+param param param
+param param param
X2 param param param
+param param param
+param param param
+param param param
X3 param param param
+**target_param** param param param
+param param param
+param param param
X4 param **target_param** param param
+param param param
+param param param
X5 param param
+param param param
X6 param param param
+param param param **target_param**
+param param param
+param param param
X7 param **target_param** param param
+param param param
+param param param
X8 param param param
+param param param
+param param param

该数据的输出为:

C:\Old_Data\perlp>perl try.pl
X1 param param param
+param param param
+param param param
X2 param param param
+param param param
+param param param
+param param param
X5 param param
+param param param
X8 param param param
+param param param
+param param param
于 2013-08-08T20:37:20.540 回答