[請益] 如何在文件中多次跨行比對
請教各位先進
如何對文件進行多次的跨行比對?
我試了幾種方法,
但結果仍然有問題;
如果在while前用$/="";的方式會變成整個文件只比對一次;
但一旦用while讀文件內容就只能一次讀一行,
變成比對不到想要的模式;
程式碼如下:
#! \strawberry\perl\bin\perl
use warnings;
use strict;
use 5.010;
use autodie;
open FILE, "<123.txt";
while (<FILE>) #也可不寫檔案代碼
{
if(/test_result: 1,2,3,4.*?test_name: iddq/sm)
{
print "match\n";
print $&;
}
}
close FILE;
想比對的文件123.txt內容如下:
dfklqwejpfwejkpofwkjp
test_result: 1,2,3,4
test_name: iddq
test_unit: uA
kdjkfjwojoew
gvaksljgwrl
hbrewhg
test_result: 12,22,33,44
test_name: iddq1
test_unit: uA
fgewgerjwogwrj
gwejqoej
test_result: 13,2,3,4
test_name: iddq
test_unit: uA
oljoifjwqeoijfweo
jfowejqoifjfeoi
test_result: 14,2,3,4
test_name: iddq
test_unit: uA
blahblahblahblah
[3.jpg]
欄位1 欄位2 欄位3 欄位4 資料1 資料2 資料3 資料4
[4.jpg]
blahblahblahblah
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.169.240.149
※ 文章網址: https://www.ptt.cc/bbs/Perl/M.1423227978.A.50B.html
推
02/06 22:49, , 1F
02/06 22:49, 1F
→
02/06 23:08, , 2F
02/06 23:08, 2F
→
02/07 00:31, , 3F
02/07 00:31, 3F
→
02/07 10:28, , 4F
02/07 10:28, 4F
→
02/07 14:32, , 5F
02/07 14:32, 5F
Perl 近期熱門文章
PTT數位生活區 即時熱門文章
10
18