Quantcast
Channel: Active questions tagged bash+awk - Ask Ubuntu
Viewing all articles
Browse latest Browse all 102

How to sum the values in multiple text files?

$
0
0

In Ubuntu desktop 20.04, I have 20 directories, each containing a text file with the same name, "weights". These text files contain ~20-30 numbers separated with a space. In each of the 20 directories, there is also a text file named "coefficient", which contains a single number.

I want to execute a shell command that goes into each directory, sums together all the numbers in the "weights" text file, and multiplies that sum by the number in the "coefficient" text file. If there was some way for this to be put into a csv that would be ideal, but even if it just prints to the terminal that would be okay too!


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>