There are a lot of logs, You need to count the number of return codes in the log records of each device by device.
The device name can be obtained based on the file name. The log records are in a certain format. The seventh field is the return code.
Both Shell and Perl are implemented, but Perl is not familiar with it, and a piece of code is spelled out on the Internet.
Use text: parsewords; <br/> Use Data: dumper; <br/> my $ result; <br/> my % table; <br/> $ argv_len = @ argv; <br/> if ($ argv_len = 0) <br/>{< br/> Print "It need filename/N "; <br/> exit (1); <br/>}< br/> $ cmd = "ls '". join ("'' ", @ argv ). "'|"; </P> <p> open (pipe, $ cmd); <br/> @ filenames = <pipe >;< br/> close (PIPE ); </P> <p> foreach (@ filenames) {<br/> analy ($ _); <br/>}</P> <p> sub trim <br/> {<br/> my $ string = shift; <br /> $ String = ~ S/^/S + //; <br/> $ string = ~ S // s + $ //; <br/> return $ string; <br/>}</P> <p> sub analy <br/>{< br/> my $ filename = trim (shift ); <br/> $ cmd = "cat $ filename |"; <br/> open (pipefile, $ cmd); <br/> @ lines = <pipefile>; <br/> close (pipefile); <br/> my ($ Sn, $ dev_id, $ time) = Split (/_/g, $ filename ); <br/> my $ Dev = $ dev_id. '-'. substr ($ Sn,-3); </P> <p> my % code; <br/> foreach (@ lines) <br/>{< br/> my @ line = quotewords ("", 1, $ _); <br/> $ code {$ line [7]} ++; <br/>}< br/> $ table {$ Dev} = [] Unless exists $ table {$ Dev }; <br/> push @ {$ table {$ Dev }},/% code; <br/>}< br/> foreach my $ Dev (sort keys % table) {<br/> Print "$ Dev:/N"; <br/> my @ code =@{$ table {$ Dev }}; <br/> foreach my $ code (@ code) <br/>{< br/> foreach my $ key (Keys (% {$ code })) <br/>{< br/> $ result {$ key} + = $ code-> {$ key }; <br/>}< br/> Print "keys/T values/N "; <br/> foreach my $ value (Keys (% result) <br/>{< br/> Print $ value. "/T ". $ result {$ value}; <br/> Print ". /n "; <br/>}< br/>}
Using shell is relatively simple, with only a few lines:
#! /Bin/sh <br/> while read line <br/> DO <br/> echo $ line <br/> grep HTTP/path/20110527/-r | grep $ line | awk '{A [$10] ++} end {for (I In) print I "" A [I]} '<br/> done <dev_list