Reputation: 631
I'm having trouble getting this perl statement to properly filter an output file.
perl -00 -wnl -e '
/Instance list size <\d+>\n(.+)\*\*end/s or die "error msg\n";
foreach my $line (split("\n", $1)) {
$line =~ /(==)$/ && print "\"$_\"" ;
}' $Output_File 2>&1
The output I'm interested is all lines terminated with ==. But for some reason, when I run this, even in a file with only 8 lines and 1 intended match, I'm getting 22 matches.
Upvotes: 1
Views: 365
Reputation: 11114
I'm not sure why you're using the -n
option and still have a foreach my $line ...
in your script. The whole point of -n
is that it will feed your script one line at a time automatically.
Here's something that works for me:
$ cat foo.txt
asdfasdfsadf asdf a== asfd a sdf
aasdf asdf asd f==
asdf asdf asdf sad fsdaf==
asdfasdfasdf sadfsadf=aa sdfasdf =
$ perl -ne "print if /==$/" < foo.txt
aasdf asdf asd f==
asdf asdf asdf sad fsdaf==
Upvotes: 2