Regex Multine替换Perl [英] Regex multine replacement perl

查看:76
本文介绍了Regex Multine替换Perl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天使人们感到困惑的是先前发布的问题,该发布的版本略有草率,但没有提供足够的信息.

Posting this question after confusing people yesterday with a slightly sloppy prior version which didn't include sufficient information.

我认为这是一个相当简单的问题,但我提供了许多上下文来帮助您.

The questions is, I think, a fairly easy one but I am providing a LOT of context to help.

因此,我有一个文件(FILEA.txt),由自动化系统创建,该文件的一个子集发布在此问题的底部,并以=== DATA ===开头.我没有发布整个文件,因为它的长度为36,000行....除非认为有必要,否则.

So, I have a file (FILEA.txt), created by an automated system a subset of that file is posted at the bottom of this question and headed as ===DATA===. I am not posting the entire file as it is 36k lines long....unless it is deemed necessary.

该文件由许多文本块组成,每个文本块都描述财务图表上的实体(线/圆/符号等).

The file consists of MANY blocks of text, each of which describe entities (lines/circles/notations etc) on financial charts.

每个块都以一致的三行开头...

Each block starts with a consistent three lines...

CHARTS
  Color=14671839
  Layer=X

其中X是从1到12的数字.因此,在下面所示文件的示例中,我们有Layer = 12.

Where X is a number from 1 through 12. So in the example from the file shown below we have Layer=12.

我已经有一个自动化过程,每天运行一次,可以将文件重新格式化为需要不同格式的用户多种格式(FILEB,FILEC,FILED等).

I already have an automated process which runs daily to reformat the file into multiple formats (FILEB, FILEC, FILED etc) for users that need different formats.

该过程由6-7个文件组成.其中有5-6个产生各种格式.这些是批处理文件,下面是示例之一:

That process consists of 6-7 files. 5-6 of them produce the various formats. These are batch files and one of the examples is below:

perl supplement.pl "s/Feed=5,8,F/Feed=3,8,F/g; s/@NQ#/NQ #F/g; s/@ES#/ES #F/g; s/@YM#/YM #F/g; s/QGC#/GC #F/g; s/QSI#/SI #F/g; s/QCL#/CL #F/g; s/QPA#/PA #F/g; s/QHG#/HG #F/g; s/QNG#/NG #F/g; s/@LB#/LBS #F/g; s/@O#/ZO #F/g; s/@RR#/ZR #F/g; s/@S#/ZS #F/g; s/@W#/ZW #F/g; s/@GF#/FC #F/g; s/@LE#/LC #F/g; s/QHO#/HO #F/g; s/@C#/ZC #F/g; s/@DX#/DX #F/g; s/AUDUSD.COMP/AUD A0-FX/g; s/USDCAD.COMP/CAD A0-FX/g; s/USDCHF.COMP/CHF A0-FX/g; s/EURUSD.COMP/EUR A0-FX/g; s/GBPUSD.COMP/GBP A0-FX/g; s/USDJPY.COMP/JPY A0-FX/g; s/NZDUSD.COMP/NZD A0-FX/g; s/@US#/ZB #F/g; s/@TY#/ZN #F/g;" c:/PATHTOFILE/FILEA.txt c:/PATHTOFILE/FILEB.txt

它读取FILEA.txt,执行转换并输出到FILEB.txt

It reads in FILEA.txt, performs the conversions and outputs to FILEB.txt

最后一个文件是一个Supplemental.pl,除了每个批处理文件中包含的格式更改外,它还从每种格式中剥离两个元素. Supplement.pl中用于删除警报行和圆圈的两行均以"$ contents =〜"开头.

The final file is a supplement.pl, which in addition to the format changes that are contained within each of the batch files, strips two elements from each and every format. The two lines in supplement.pl that strips out alert lines and circles each start with "$contents =~".

我希望添加第三条条"线,以在WHERE Layer = 7的整个范围内去除每个块.我认为这将一直查找Charts/n Color = 14671839/n Layer = 7直到下一个图表",然后将其替换为"Charts",这意味着先前的方块消失了.我希望这是有道理的.

I am looking to add a third 'strip' line that strips out each block in its entirety WHERE Layer=7. I figured this would look for Charts/n Color=14671839/n Layer=7 all the way through to the next "Charts" and replace the lot with "Charts" meaning the prior block vanishes. I hope this makes sense.

我尝试在此处进行全面介绍,但如果有帮助,我很乐意提供其他信息.

I have tried to be comprehensive here but I am happy to provde additional information if it helps.

=== START SUPPLEMENT.PL ===

===START SUPPLEMENT.PL===

#!/usr/bin/perl

$sub = shift @ARGV;
$input = shift @ARGV;
$output = shift @ARGV;


open INPUT, "<","$input" or die $!;         
open OUTPUT, ">","$output" or die $!;           

local $/ = undef;
$contents = <INPUT>;

@subs = split('; ', $sub);
foreach (@subs)
{
    @re = split( m/(?<!\\)\//, $_);
    tr/\\//d for @re;

    $contents =~ s/$re[1]/$re[2]/g;
}

$contents =~ s/\[19\]\= <<<\s+Circle(?s).*?\[28\]\=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,//g;
$contents =~ s/\[19\]\= <<<\s+Draw Line Alarmed(?s).*?\[28\]\=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,//g;
===NEED STRIP NEW LINE HERE===

print OUTPUT $contents;

close INPUT;
close OUTPUT;

=== END SUPPLEMENT.PL ===

===END SUPPLEMENT.PL===

==开始样本数据===

==START SAMPLE DATA===

CHARTS
  Color=14671839
  Layer=12
  [0] Font=MS SAN SERIF,10,0,F,F,
  [1] Show=F,F,F,T,T,F,T,F,F,T,
  [2] Scale=F,F,T,F,F,F,F,F,0,T,F,
  [3] Grid=F,F,F,F,1,
  [4] Paint=F,F,F,0,0,0,
  [5] Bars=1,2000,1970,
  [6] Colors=65793,0,0,8388608,32767,65793,0,0,
  [7] Theme=6,0,255,65280,7566080,0,16777215,0,
  [8] Candles=F,F,F,F,1,F,
  [9] Filter=T,F,F,F,F,0,0
  [10] Type=F,F,F,F,15,44656,
  [11] Spacing=3,49,0,10,4,-7,73,
  [12] Range=56.16,18.72,0.01,0.01
  [13] Volume=0,100,0,0,0,0,
  [14] Refresh=0,0,0,
  [15] Feed=5,1,F,
  [16] Template=
  [17] Symbol=XLP.W
  [18] SubSizes=0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Note: SPDR Consumer Staples Sector   >>>
  [20]=76,44700,0,0,513,2304,29325,4158,10,59619,29671,10589,21907,2496,29325,4158,10,
  [21]=-2083405824,1,0,8388608,255,16711680,16711680,16711680,16711680,11842740,0,0,0,0,0,0,32,32,32,32,32,32,32,32,
  [22]=-2083405705,1,1035611788,-1096111445,1151639552,1101497088,1147076608,1435707648,1696464,5525461,1921845696,659518,13,29,182101436,1696464,1696712,1696552,139104368,4830724,1696712,2,1696712,4225200,139104368,1696552,
  [23]=8,0,2,67167744,1150116,0,1150116,67137536,1150828,0,0,0,0,0,0,1,1,1,1,3,1,0,0,0,0,
  [24]=0,71,1,0,0,0,0,0,0,0,0,0,0,84,0,0,0,0,0,0,0,0,28,83,80,68,82,32,67,111,110,115,117,109,101,114,32,83,116,97,112,108,101,115,32,83,101,99,116,111,114,
  [25]=255,242,118,160,226,25,0,80,120,35,2,0,0,0,0,71,1,0,0,0,0,0,0,0,0,0,0,213,15,122,1,240,27,244,118,0,0,0,0,252,36,11,116,152,13,232,115,116,20,35,
  [26]=0,71,1,0,0,236,162,218,10,0,0,0,0,192,73,156,1,177,2,0,0,0,0,0,0,24,198,216,10,28,0,0,0,166,13,232,115,42,0,0,0,16,227,25,0,92,15,167,118,36,
  [27]=163,218,10,252,197,216,10,28,0,0,0,0,0,0,0,224,228,25,0,228,4,0,0,105,15,167,118,110,115,117,109,0,0,0,0,28,0,0,0,0,0,0,64,1,0,0,0,68,227,25,
  [28]=5506571,1696712,139104368,139104368,5506571,1696712,139104368,139104368,1944577216,24776661,0,327,0,0,3366912,1,1435707981,-2147483648,1995709424,327,0,0,0,2298996,0,

  [19]= <<<    Line     h    19.28    58.58   >>>
  [20]=65,44701,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,118.33334,0,118.33334,19.2794,58.58068,58.58068,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=1,0,0,0,1161209,0,1161209,255,1090313,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     i    45.35    84.64   >>>
  [20]=65,44702,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,359.66666,0.33333,359.66666,45.34758,84.64344,84.64344,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=1,0,0,0,1161209,0,1161209,255,1131025,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

CHARTS
  Color=14671839
  Layer=12
  [0] Font=MS SAN SERIF,10,0,F,F,
  [1] Show=F,F,F,T,T,F,T,F,F,T,
  [2] Scale=F,F,T,F,F,F,F,F,0,T,F,
  [3] Grid=F,F,F,F,1,
  [4] Paint=F,F,F,0,0,0,
  [5] Bars=1,2000,1970,
  [6] Colors=65793,0,0,8388608,32767,65793,0,0,
  [7] Theme=6,0,255,65280,7566080,0,16777215,0,
  [8] Candles=F,F,F,F,1,F,
  [9] Filter=T,F,F,F,F,0,0
  [10] Type=F,F,F,F,15,44657,
  [11] Spacing=10,261,0,10,4,-7,73,
  [12] Range=53.46,41.04,0.01,0.01
  [13] Volume=0,100,0,0,0,0,
  [14] Refresh=0,0,0,
  [15] Feed=5,1,F,
  [16] Template=
  [17] Symbol=EWW.W
  [18] SubSizes=0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     p    57.74    31.41   >>>
  [20]=65,47387,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,82.25,0,82.25,57.74,31.41068,31.41068,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=1,0,0,0,1161209,0,1161209,255,1130628,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     q    77.54    51.23   >>>
  [20]=65,47388,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,65.5,0.25,65.5,77.53828,51.22672,51.22672,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=1,0,0,0,1161209,0,1161209,255,1130301,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     r    62.76    36.45   >>>
  [20]=65,47389,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,165.25,0,165.25,62.75862,36.44707,36.44707,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=1,0,0,0,1161209,0,1161209,255,1150130,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

CHARTS
  Color=14671839
  Layer=12
  [0] Font=MS SAN SERIF,10,0,F,F,
  [1] Show=F,F,F,T,T,F,T,F,F,T,
  [2] Scale=F,F,T,F,F,F,F,F,0,T,F,
  [3] Grid=F,F,F,F,1,
  [4] Paint=F,F,F,0,0,0,
  [5] Bars=1,2000,1970,
  [6] Colors=65793,20480,1376384,8388608,32767,65793,0,0,
  [7] Theme=6,0,255,65280,7566080,0,16777215,0,
  [8] Candles=F,F,F,F,1,F,
  [9] Filter=T,F,F,F,F,0,0
  [10] Type=F,F,F,F,15,44658,
  [11] Spacing=3,290,0,10,4,-7,73,
  [12] Range=39.6,7.92,0.62,0.01
  [13] Volume=0,100,0,0,0,0,
  [14] Refresh=0,0,0,
  [15] Feed=5,1,F,
  [16] Template=
  [17] Symbol=XHB.W
  [18] SubSizes=0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     o    19.94    43.15   >>>
  [20]=65,9114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,27.5,0,27.5,19.94,43.1505,43.1505,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=1,0,0,0,1160101,0,1160101,255,1100423,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     p     7.96    31.18   >>>
  [20]=65,9115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,-0.25,0.25,-0.25,7.95896,31.18213,31.18213,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=3,0,0,0,1150605,0,1150605,255,1090313,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     q    11.20    34.43   >>>
  [20]=65,9116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,88.75,0.25,88.75,11.20242,34.42559,34.42559,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=3,0,0,0,1160101,0,1160101,255,1110624,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Line     r    18.50    41.72   >>>
  [20]=65,9117,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [21]=16711680,16711680,8421376,0,255,255,16711680,16711680,65280,16744447,32767,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [22]=0,0,133,0.5,133,18.5002,41.72338,41.72338,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
  [23]=3,0,0,0,1160101,0,1160101,255,1120427,1,2,2,1,0,1,1,1,1,1,1,1,0,0,0,0,
  [24]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [25]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [26]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [27]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  [28]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

  [19]= <<<    Note: SPDR Homebuilders ETF   >>>
  [20]=76,44659,0,0,513,63488,25,5552,29674,39301,9851,27405,26412,63420,25,2963,29325,
  [21]=-2083405824,1,0,8388608,255,16711680,16711680,16711680,16711680,11842740,0,0,0,0,0,0,32,32,32,32,32,32,32,32,
  [22]=-2083405705,1,1056964608,1106597205,1155792896,1090936302,1146437632,0,1,0,0,112,-1,-1,1944577820,1944579083,0,0,0,0,0,1921845696,0,31918584,0,16,
  [23]=

== END样本数据===

==END SAMPLE DATA===

推荐答案

因此,根据您的问题:

我希望添加第三条条"线,以去除其中的每个块 整个 WHERE Layer = 7 .

I am looking to add a third 'strip' line that strips out each block in its entirety WHERE Layer=7.

您是否注意到,示例数据中是否没有包含Layer=7的部分?

Did you noticed, that in your sample data isn't any section containing Layer=7?

现在解决方案:

完全是您的代码,并在注释中添加了一行(例如,您之前的相同内容的答案中)问题.

Excetly your code, with the added line from the comments (e.g. from the answers to your previous same question.

#!/usr/bin/perl

$sub = shift @ARGV;
$input = shift @ARGV;
$output = shift @ARGV;


open INPUT, "<","$input" or die $!;         
open OUTPUT, ">","$output" or die $!;           

local $/ = undef;
$contents = <INPUT>;

@subs = split('; ', $sub);
foreach (@subs)
{
    @re = split( m/(?<!\\)\//, $_);
    tr/\\//d for @re;

    $contents =~ s/$re[1]/$re[2]/g;
}

$contents =~ s/\[19\]\= <<<\s+Circle(?s).*?\[28\]\=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,//g;
$contents =~ s/\[19\]\= <<<\s+Draw Line Alarmed(?s).*?\[28\]\=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,//g;

#this is the added line
$contents = join '', grep { !/Layer\s*=\s*7\b/ } split /^(?=CHARTS)/m, $contents;
#or this works too
#$contents = join 'CHARTS', grep { !/Layer\s*=\s*7\b/ } split /\bCHARTS\b/, $contents;

print OUTPUT $contents;

close INPUT;
close OUTPUT;

以上:

  • 已针对您的数据进行了测试.
  • 它产生输出.
  • 而且,如果您在输入数据中包含一些包含Layer=7CHARTS section,则会将其删除.
  • Is tested against your data.
  • It produces output.
  • And, if you will have in the input data some CHARTS section containing Layer=7 it will be removed.

这篇关于Regex Multine替换Perl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆