Created
January 13, 2014 15:00
-
-
Save egulhan/8401786 to your computer and use it in GitHub Desktop.
Scripting methods to sum numbers in a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scripting methods to sum numbers in a file: | |
------------------------------------------- | |
- awk '{s+=$1} END {print s}' number-list-file | |
- paste -s -d+ number-list-file|bc | |
- sum=0; while read num ; do sum=$(($sum + $num)); done < number-list-file ; echo $sum | |
- php -r '$sum=0;foreach(file("number-list-file") as $line) $sum+=$line;echo $sum.PHP_EOL;'; | |
- cat number-list-file | php -r "echo array_sum(explode(PHP_EOL, stream_get_contents(STDIN)));" | |
- cat number-list-file | xargs | sed -e 's/\ /+/g' | bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment