2017-04-03 45 views
1

昨日發佈此問題後,人們以前的版本略顯草率,但沒有包含足夠的信息。正則表達式multine replacement perl

問題是,我認爲這是一個相當簡單的問題,但我提供了很多幫助的背景。

所以,我有一個文件(FILEA.txt),由自動化系統創建該文件的子集發佈在這個問題的底部,並以===數據===爲首。我不發佈整個文件,因爲它是36k行長....除非它被認爲是必要的。

該文件由多個文本塊組成,每個文本塊描述金融圖表上的實體(線/圈/記號等)。

每個塊具有一致的三行開始...

CHARTS 
    Color=14671839 
    Layer=X 

當X是一個從1到12因此,在從該文件的例子顯示在下面,我們有層= 12。

我已經有一個自動化的過程,每天都會爲需要不同格式的用戶重新格式化文件爲多種格式(FILEB,FILEC,FILED等)。

該進程由6-7個文件組成。其中5-6個產生各種格式。這些是批處理文件和其中一個例子是以下:

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

最終文件是一個supplement.pl,其在除了每個批處理文件中包含的格式更改外,還可以從每種格式中除去兩個元素。 supplement.pl中的兩行刪除警戒線和圓圈,每個都以「$ contents =〜」開頭。

我正在尋找添加第三個「帶」線,其中每個塊的完整剝去WHERE層= 7。我認爲這將查找Charts/n Color = 14671839/n Layer = 7直到下一個「圖表」,並用「圖表」替換該圖表,表示前面的圖塊消失。我希望這是有道理的。

我試圖在這裏全面,但我很樂意提供額外的信息,如果它有幫助。

=== 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 ===

== START樣本數據===

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 SAMPLE DATA ===

+2

老實說,我仍然沒有得到你想要的東西 - 因爲:你的輸入數據包含太多不必要的部分,主要是因爲你錯過了添加WANTED輸出... :) [mcve]是個好東西事情。 – kobame

+0

我沒有詳細說明上面的輸出。我需要從圖表...中移除整個圖塊到下一圖表WHERE圖層= 7。 我真的不知道如何闡明這一點。對不起,這實際上是一個非常簡單的要求,但我似乎無法溝通它。 – PaulC

+0

昨天我已經回答了你的問題。將'=== NEED STRIP NEW LINE HERE ==='替換爲'$ contents = join'CHARTS',grep {!/ Layer \ s * = \ s * 7 \ b /} split/\ bCHARTS \ b/,$ contents;'(來自[昨天的回答](http://stackoverflow.com/a/43168103/632407),你就完成了。你也可以使用任何其他的答案,如'$ contents = join'' ,grep {!/ Layer \ s * = \ s * 7 \ b /} split/^(?= CHARTS)/ m,$ contents'。兩者都解決了這個問題, – jm666

回答

0

所以,從你的問題:

我正在尋找添加第三條「strip」線,它將 中的每個塊全部去掉WHERE圖層= 7

您是否注意到,您的樣品數據中沒有包含Layer=7的任何部分?

現在的解決方案:

Excetly代碼,從註釋添加的行(例如,從答案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; 

以上。

  • 是根據您的數據進行測試
  • 它產生輸出。
  • 而且,如果您在輸入數據中有一些CHARTS section包含Layer=7它將被刪除。
+0

非常感謝您的支持。它工作正常。我現在看到我的問題是缺少打印輸出行。 對不起,如此緩慢,這不是我的特長,我感謝你的耐心。 – PaulC

+0

@PaulC yw並享受。 :)你也可以閱讀:[我應該怎麼做當有人回答我的問題?](http://stackoverflow.com/help/someone-answers) – jm666

+0

我只是想跟進@ jm666在這個。我試圖在您發佈該解決方案時對此解決方案進行投票,但顯然我的聲譽不足(<15),因此我沒有被允許投票。我雖然能夠選擇它作爲答案。我今天回來問一個後續問題,看看我的名譽現在是神祕的16,所以我投票。很抱歉,如果我沒有給你提供解決方案的道具並且再次感謝你,我就消失了。 – PaulC