Next | Welcome to my ~/bin | 8 |
#!/usr/local/bin/perl -na $total += $F[0];
END {print $total, "\n" }
But I found I was still using awk
awk '{t += $7} END {print t}'
So the current version of addup is a little more flexible:
#!/usr/local/bin/perl -na BEGIN { $fieldno = shift } $total += defined($fieldno) ? (split(/\s+/))[$fieldno-1] : $_;
END{print $total, "\n" }
Typical usages:
ls -l | addup 4 # add up sizes of files
# Add up sizes of web requests grep '/book/' logs/perl-access_log | addup 10
Next | Menu | Copyright © 2005 M. J. Dominus |