http://qs321.pair.com?node_id=1017891


in reply to perl onliner on multiple files

Seems to work fine (on a reasonable number of files) if you want the total sum. If you want the sum per file, a minimal change would be to print and reset $c after each file ends.

For example:
perl -e ' while (<>) { if (/: /) { $c += (split /: /)[0]; } if(eof) { print "SUM.$ARGV =$c\n"; $c=0; } }' tmp_*

Replies are listed 'Best First'.
Re^2: perl onliner on multiple files
by abhay180 (Sexton) on Feb 09, 2013 at 10:12 UTC
    Great...it works.