我有一个Perl脚本,当前抓取包含单词ACCOUNT
的每一行。我怎样才能在行的开头抓取包含单词ACCOUNT
的行?
use strict;
my $find = 'ACCOUNT';
open (NEW, ">", "output.txt" ) or die "could not open:$!";
open (FILE, "<", "Report.txt") or die "could not open:$!";
while (<FILE>) {
print NEW if (/$find/);
}
close (FILE);
close (NEW);
答案 0 :(得分:2)
评论了空白版,因为人们似乎没有阅读评论。
use strict;
my $find = 'ACCOUNT';
open (NEW, ">", "output.txt" ) or die "could not open:$!";
open (FILE, "<", "Report.txt") or die "could not open:$!";
while (<FILE>) {
# print NEW if $_ =~ /^\s*$find/ ; # Any line that starts with whitespace and followed by $find
print NEW if $_ =~ /^$find/ ; # Any line that starts strictly with $find
}
close (FILE);
close (NEW);