Summing a list of numbers

Posted by Chief on Oct 15, 2009 in Scripts, Tricks and Hacks
No Comments

awk '{sum += $0} END {print sum}'

Example:
% find . -type f -exec wc {} \; | tr -s " " | cut -f2 -d" " | awk '{sum += $0} END {print sum}'

What’s going on? I want to recursively count the number of lines present in all files contained by the current directory. Why? Sub-directories => namespaces, and I want to know how many lines of code exist in the entire project, namespaces and all.

Tags: , ,

Copyright © 2010 cat brain.log | less All rights reserved.
Shades v1.2 theme from BuyNowShop.com.