I have a file whose columns contain simple arithmetic equations that I would like to merge to the arithmetic result.
Input sample (tab-separated columns):
+104-1+12 6 +3
I would like to compute the arithmetic sum within each column. If one column contains no arithmetic sign, I treat it as it contained a
+ before the item. Although it would be easy through sed to add a
+ sign if a column starts with no sign (
sed -E 's/(\t)([0-9]*)/\1\t+\2/g' would work, assuming that a row never begins with a digit, as in the example)
The output I would expect is the following:
115 6 3
How can I achieve this in unix? awk/sed solutions are preferred.