I have a question to add a column title during a loop with awk: I currently have this code, which calculates the mean of each line for each csv file :
for i in *.csv; do
awk -F"," 'NR==1 { next }
{ T=0
for(N=1; N<=NF; N++) T+=$N;
T/=NF
print T }' $i > Mean$i
done
So I get files MeanName1.csv, MeanName2.csv, ... containing:
2.5 3.5 ...
4.2 3.4
1.2 3.9
1.2 3.7
I would like to get a single file "Mean" containing:
Name1 Name2 ...
2.5 3.5
4.2 3.4
1.2 3.9
1.2 3.7
I failed to use print FILENAME in the loop.
Do you have any suggestions ? Thank you