2
1
I'd like to sum up numbers in a plain text file. Is there somehow I can do this with a command or a bash script?
Say I want to extract the number in a pattern that looks like this:
… text text …
Removed 50 items out of 50 items.
… text text …
Removed 34 items out of 50 items.
… text text …
So in the case above, I'd like to extract the first number in the lines that they pop up and sum it up. In the example the result should be 84. I know how to grep it, but that's the extent of my knowledge of *nix commands.
4Grep to filter for the lines, cut to isolate the numbers, awk to sum up numbers. – Daniel Beck – 2011-06-27T11:42:23.123
awk can duplicate the functionality of grep and cut, so why not just use awk alone? – Stephanie – 2011-07-11T02:13:19.433