Results 1 to 2 of 2
Hi everyone, just some simple question...
i've been using a awk script to calculate my data...
i have 3 files:
file a1.txt:
2
3
4
5
3
4
file a2.txt:
...
- 05-24-2011 #1Just Joined!
- Join Date
- May 2011
- Posts
- 5
Calculate data and make it into new column using awk
Hi everyone, just some simple question...
i've been using a awk script to calculate my data...
i have 3 files:
file a1.txt:
2
3
4
5
3
4
file a2.txt:
4
5
6
7
8
file a3.txt:
2
5
1
3
4
i successfully calculate the average of each file using awk:
awk '{ s += $1 } END { print s/NR }' a1.txt
awk '{ s += $1 } END { print s/NR }' a2.txt
awk '{ s += $1 } END { print s/NR }' a3.txt
the results were (3.5, 6 and 3) which is pretty easy..
now i want to combine all this into 1 file and each have different columns and called it avg.txt which have something like this in the end:
3.5 6 3
help is much appreciated, Tq
- 05-25-2011 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Code:awk 'NR==1{s=$1; f=FILENAME; next} f != FILENAME {a=a?a FS s/n:s/n ; f=FILENAME; s=0} {s+=$1; n=FNR} END{print a, s/n}' a1.txt a2.txt a3.txt


Reply With Quote