Perl 脚本

Posted by Liang Chen on August 27, 2021
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/perl

my $value;
$value = open(file1, "< synth.log");
if ($value) {
  print "file open successfully!\n";
}
else {
  die "file open failed!\n";
}

open(file2, "> Error.rpt");

my $line;
while (<file1>) {
  $line = $_;
  if ($line =~ m/Error/) {
    print "Match:Error\n";
    print file2 "$. : $line";
  }
}

close(file1);
close(file2);