Quantcast
Viewing all articles
Browse latest Browse all 102

How to calculate average of 2nd field from files?

I have many files.

Files format as follows

  • cccedddh.yyi

where

  • ddd: 3-digit the day of the year
  • yy : 2-digit year

Example: jplg0010.19i

The files consist of two fields. I want to print output as yyyy-mm-dd(or yyyy-mm-ddT00:00:00) mean (average 2nd values from files)

For example for file of jplg0010.19i

2019-01-01T00:00:00 5 (let's say mean value is 5)

or

01-01-2019 5

I could calculate mean.

awk '{ sum += $2; count++ } END { print sum/count }'

However, I didn't convert values into date format from filename.

How do I do it for each files and then print in one file?


Viewing all articles
Browse latest Browse all 102


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