Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active April 12, 2018 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greymd/079c4964f04ab03003f35c7e5a9c8dc1 to your computer and use it in GitHub Desktop.
Save greymd/079c4964f04ab03003f35c7e5a9c8dc1 to your computer and use it in GitHub Desktop.
sum digits in the line
# https://unix.stackexchange.com/questions/205936/how-can-i-quickly-sum-all-numbers-in-a-file/205939
perl -pe 's/\d*/$s+=$&/ge}{$_=$s' file
perl -F= -pe '$s+=$F[1]}{print $s' file
awk -F= '{sum+=$2};END{print sum}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment