Hi i am writing a perl. script to extract out the number of errors with each code as a summary. The input is like this
A_01: xxxxxxx xxxxxxxxxx xxx......... 1 violation A_02: xxxxxxx xxxxxxxxxx xxx......... 4 violations B_02: xxxxxxxx xxxxxxxxxx xxx......... 3 violations
So, from the input, basically i have to grep from A_01 until 1 violation, and from here to there is about 3 lines, and the output is like this:
A number of violations = 5; B number of violations = 3;
But, my code is only able to read the violations all though, and sum it out. My code is like tis:
open(DATA, "<abc.txt, $!"; $num = 0; while (<DATA>){ while (<DATA>){ if ( (($_ =~ /violation/) || ($_ =~ /violations/))) { if ($_ =~ /(\d+)/) { $num = $num + $1; } } } if ($num == 0) { print "DM0$x ....... CLEANED\n" } else { print "DM0$x ....... Total = $num violations\n" } }
In reply to grep the data out of a text file. by DespacitoPerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |