Reputation: 415
As I said, I got answer from here: AWK multiple files averge
However, that is not enough if I have multiple files dummy_0.txt dummy_100.txt dummy_200.txt... dummy_5000.txt ... dummy_50000.txt
.
I only want to average column 2 of files range from dummy_0.txt to dummy_5000.txt.
Instead of doing this:
awk '{a[FNR]+=$2;b[FNR]++;}END{for(i=1;i<=FNR;i++)print i,a[i]/b[i];}' dummy_*.txt
I need something like where interval is 100
awk '{a[FNR]+=$2;b[FNR]++;}END{for(i=1;i<=FNR;i++)print i,a[i]/b[i];}' dummy_[100 - 5000].txt
How can I do it?
Upvotes: 1
Views: 139
Reputation: 785156
You can use glob range {start..end..interval}
in bash:
awk '{a[FNR]+=$2; b[FNR]++}
END{for(i=1;i<=FNR;i++) print i,a[i]/b[i]}' dummy_{100..5000..100].txt
Upvotes: 1