我想使用Perl解析文本文件。此文本文件包含一些HTML文件的日誌,如下所示:解析HTML日誌文件並獲取特定格式的文本文件
Details from /projects/git/Changelog.html file:
NEW_FEATURES: <a href="http://jira.xyz.com/browse/JIRA-4208">JIRA-4208</a><span style='mso-spacerun:yes'> </span>Add New Config C support in code
BUG_FIX: <a href="http://jira.xyz.com/browse/BUGJIRA-31">BUGJIRA-31</a><span style='mso-spacerun:yes'> </span>Bugfix of some old bug
NEW_FEATURES: <a href="http://jira.xyz.com/browse/ZEERA-273">ZEERA-273</a><span style='mso-spacerun:yes'> </span>Add support for some other feature.
Details from /projects/git/Changelog2.html file:
BUG_FIX: <a href="http://jira.xyz.com/browse/BUGJIRA-33">BUGJIRA-33</a><span style='mso-spacerun:yes'> </span>Bugfix of an issue
NEW_FEATURES: <a href="http://jira.xyz.com/browse/JIRA-4209">JIRA-4209</a><span style='mso-spacerun:yes'> </span>Add New Config D support in code
每行包含一個Bug編號及其說明。
解析後,將期望的輸出是如下:
JIRA-4208, BUGJIRA-31, ZEERA-273, BUGJIRA-33, JIRA-4209 : Add New Config C support in code, Bugfix of some old bug, Add support for some other feature, Bugfix of an issue, Add New Config D support in code
即,所有的錯誤數,隨後對它們的描述。
如果可能的話我還想寫輸出在另一個文件中output.txt
編輯-1:
我的代碼下:
#!/usr/bin/perl
open (FILE, 'input_file1.txt') or die "Could not read from file, exit...";
while(<FILE>)
{
chomp;
($junk0,$junk1,$junk2,$junk3,$junk4,$BUG_NUMBR) = split /[:<="">]+/,$_;
print "$BUG_NUMBR \n";
}
close FILE;
exit;
,輸出是:
JIRA-4208
BUGJIRA-31
ZEERA-273
BUGJIRA-33
JIRA-4209
這與預期的輸出大不相同,如圖所示五個。我無法爲預期輸出的第二部分定義合適的正則表達式,這是對錯誤的簡短描述。
那你究竟試過了什麼?什麼不能在你的代碼中工作?這裏有什麼問題? –
@ChrisDoyle:我已經添加了示例代碼並解釋了它的侷限性。請求您提出解決方案。 – Yash
你真的想要一個所有錯誤編號的列表,然後是所有描述的列表嗎? –