本月早些时候我有a recent question由@ jm666解决,涉及多行文字替换。
我遇到了一个问题,虽然这可以按照要求完美运行,但它会删除文本文件末尾的一些文本,我需要保留这些文本。
添加到我的流程文件中的行删除了文本块,如下所示:
$contents = join '', grep { !/Layer\s*=\s*7\b/ } split /^(?=CHARTS)/m, $contents;
下面的数据显示了被剥离的内容。每个文本块以CHARTS
开头,以[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
开始。
问题开头显示的行正确地删除了每个整个块(从开始到结束)Layer=7
,其位于每个块的第4行。
然后,文件中的最后一个块后跟一些格式化的信息。该信息以STACK
开头。在下面的示例代码下方,我会显示STACK
信息。
我发布了a 2 min video,详细描述了该问题
CHARTS
Position=574,1988,1013,2652,-1,-1
Color=14671839
Layer=7
[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,5083,
[11] Spacing=5,236,0,10,4,-7,73,
[12] Range=227.8,107.2,2.05,0.01
[13] Volume=0,100,0,0,0,0,
[14] Refresh=0,0,0,
[15] Feed=5,5,F,
[16] Template=
[17] Symbol=@OJ#.W
[18] SubSizes=0,0,0,0,0,0,0,0,0,0,
[19]= <<< Andrews Pitchfork 1 >>>
[20]=61,5085,0,1,192,0,0,0,0,0,0,0,0,0,0,0,0,
[21]=16711935,16711935,16711935,255,16711935,255,16711935,16711935,65793,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
[22]=2,7,0,0,0,64.58475,226.99976,97.1011,35,2,0,0,25,38.2,50,61.8,75,100,0,0,0,0,0,0,0,0,
[23]=146,0,0,2,1120518,0,1120127,255,1090220,1,3,3,1,1,4,1,1,3,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,2,0,0,0,0,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]= <<< c:\XXXXX\Alerts\AUD.wav 103.47 672.59 >>>
[20]=65,5088,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,
[21]=65280,65280,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,0,2730.6001,103.47184,672.59155,103.47184,5,0,0,0,0,0,0,1,0,0.1,0,0,0,0,0,0,0,0,
[23]=3,0,0,0,1120914,0,1170120,255,1120914,1,5,5,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,26,99,58,92,69,110,115,105,103,110,49,
[25]=48,92,65,108,101,114,116,115,92,65,85,68,46,119,97,118,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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0,0,0,
CHARTS
Position=-462,3460,-23,4124,-1,-1
Color=14671839
Layer=1
[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,43286,
[11] Spacing=5,183,0,10,4,-7,73,
[12] Range=148.5,89.1,0.01,0.01
[13] Volume=0,100,0,0,0,0,
[14] Refresh=0,0,0,
[15] Feed=5,2,F,
[16] Template=
[17] Symbol=SVXY.D
[18] SubSizes=0,0,0,0,0,0,0,0,0,0,
[19]= <<< Circle >>>
[20]=62,43296,0,0,576,0,0,0,0,0,0,0,0,0,0,0,0,
[21]=13959167,16711680,65280,255,255,5242880,16744192,12900,255,5242880,16727871,0,0,0,0,0,0,0,0,0,0,0,0,0,
[22]=2,7,0,0,-0.28571,134.64,135.71358,134.62071,15,0,0,0,25,38.2,50,61.8,75,100,150,161.8,200,0,0,0,0,0,
[23]=130,2,0,2,1170222,1,1170222,1,1170215,0,2,0,1,1,1,1,1,3,1,1,1,0,0,0,0,
[24]=176,0,0,0,0,0,0,0,0,0,0,177,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,25,0,117,4,119,0,216,250,25,
[25]=0,64,202,15,5,4,182,73,0,168,233,105,179,2,0,0,0,117,4,119,0,176,120,64,0,64,202,15,5,32,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]= <<< Circle >>>
[20]=62,43297,0,0,576,0,0,0,0,0,0,0,0,0,0,0,0,
[21]=13959167,16711680,65280,255,255,5242880,16744192,12900,255,5242880,16727871,0,0,0,0,0,0,0,0,0,0,0,0,0,
[22]=2,7,1.85714,-0.14286,1.57143,145.22144,146.31429,145.22144,15,0,0,0,25,38.2,50,61.8,75,100,150,161.8,200,0,0,0,0,0,
[23]=130,2,0,2,1170323,1,1170323,1,1170321,0,2,0,1,1,1,1,1,3,1,1,1,0,0,0,0,
[24]=176,0,0,0,0,0,0,0,0,0,0,177,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,25,0,117,4,119,0,216,250,25,
[25]=0,64,202,15,5,4,182,73,0,168,233,105,179,2,0,0,0,117,4,119,0,176,120,64,0,64,202,15,5,32,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]= <<< Circle >>>
[20]=62,44362,0,0,576,0,0,0,0,0,0,0,0,0,0,0,0,
[21]=13959167,16711680,65280,255,255,5242880,16744192,12900,255,5242880,16727871,0,0,0,0,0,0,0,0,0,0,0,0,0,
[22]=2,7,0.09091,0,0.09091,63.96,63.93712,63.93712,15,0,0,0,25,38.2,50,61.8,75,100,150,161.8,200,0,0,0,0,0,
[23]=130,2,0,2,1161108,1,1161108,1,1161104,0,2,0,1,1,1,1,1,3,1,1,1,0,0,0,0,
[24]=176,0,0,0,0,0,0,0,0,0,0,177,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,250,25,0,123,2,159,3,216,250,25,
[25]=0,64,202,15,5,4,182,73,0,168,233,105,179,2,0,0,0,123,2,159,3,176,120,64,0,64,202,15,5,32,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
数据块的最后两行。如您所见,然后是许多较小的块,以STACK
开头。
这个问题只是在问题开头寻找对代码行的修改,再次在下面复制,而不是删除STACK
块。使用当前解决方案,它会删除所有Layer=7
块,但它也会删除文件末尾的所有STACK
块。尽管STACK
块之前的最后一段文字为Layer=1
,而不是Layer=7
。
$contents = join '', grep { !/Layer\s*=\s*7\b/ } split /^(?=CHARTS)/m, $contents;
[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,
STACK
Position=399,390,888,1211,0,1048
Color=-16777201
Layer=6
ID=56729,56730,56731,56732,56733,56734,56735,
[1] Name=
[2] Index=1,
[3] Pinned=F,
[4] Font=8,-16777208,F,MS SANS SERIF
Window=Minimized
STACK
Position=399,684,888,1348,0,1048
Color=-16777201
Layer=1
ID=28487,9939,
[1] Name=
[2] Index=0,
[3] Pinned=F,
[4] Font=8,-16777208,F,MS SANS SERIF
Window=Minimized
STACK
答案 0 :(得分:0)
提供STACK
块只发生在文件的末尾,您可以尝试拆分STACK
块:
$contents = join '', grep { /^STACK/ || !/Layer\s*=\s*7\b/ } split /^(?=CHARTS|STACK)/m, $contents;