我正在尝试让这个脚本适用于两个查找字符串。我无法获取文件以导出我正在寻找的格式。
use strict;
my $find = '^(H0|HT)';
open (NEW, ">", "output.txt" ) or die "could not open:$!";
open (FILE, "<", "input.txt") or die "could not open:$!";
while (<FILE>) {
chomp;
if (/^\h{39}\XX187/){
print NEW join(",","$_\n");
}
if (/$find/){
print NEW join(",","$_")
}
}
close (FILE);
close (NEW);
输入文件:
Txn Bch
Account Patient Name Date
--------------------------------------------------------------------------------------------
HT12345678 TEST,TESTNAME 01/01/16
XX187 CLAIM PROCESSED 01/01/16
输出文件(期望):
HT12345678 TEST, TESTNAME 01/01/16 XX187 CLAIM PROCESSED 01/01/16
答案 0 :(得分:1)
你的问题非常不精确,我无法准确理解你需要什么。但是,这个简短的计划可能会有所帮助
use strict;
use warnings 'all';
while ( <DATA> ) {
print if /^(?:H[0T]|\s+XX187\b)/;
}
__DATA__
Account Patient Name Date
--------------------------------------------------------------------------------------------
HT12345678 TEST,TESTNAME 01/01/16
XX187 CLAIM PROCESSED 01/01/16
HT12345678 TEST,TESTNAME 01/01/16
XX187 CLAIM PROCESSED 01/01/16