Hi!
Could you please help to modify the following awk code (script) to shorten it. This code goes through different files and calculates the mean and standard deviation of the last value in the second column. Now it is done in ``stupid'' way, i.e., if I want to add one more data set I would need to change a parameter N everywhere and add manually corresponding file name. Furthermore, adding different data corresponding to a parameter w (omega) would require adding one more block of the code. Though, since all these blocks have a similar structure I wounder if it is possible to make it easier with awk, i.e., have an array of different w (omega) I would like to process, and a parameter N corresponding to a number of files I need to process.
Thank you for your help and time.
Could you please help to modify the following awk code (script) to shorten it. This code goes through different files and calculates the mean and standard deviation of the last value in the second column. Now it is done in ``stupid'' way, i.e., if I want to add one more data set I would need to change a parameter N everywhere and add manually corresponding file name. Furthermore, adding different data corresponding to a parameter w (omega) would require adding one more block of the code. Though, since all these blocks have a similar structure I wounder if it is possible to make it easier with awk, i.e., have an array of different w (omega) I would like to process, and a parameter N corresponding to a number of files I need to process.
Thank you for your help and time.
Code:
<html>
<head>
<title>Page</title>
</head>
<body>
awk '{ Nu[f]=0; {Nu[f] = $2}} END { N=3; mu=0; for(i=1;i<=N;i++) {mu += Nu[i]} mu /= N; sigma=0; for(i=1;i<=N;i++) {sigma += (Nu[i]-mu)^2} sigma = sqrt(sigma/N);
print 2 " " mu " " sigma}' f=1 ./_TUS+/N=4096/w=2/OUTPUT_ED/pre f=2 ./_TUS+_1/N=4096/w=2/OUTPUT_ED/pre f=3 ./_TUS+_2/N=4096/w=2/OUTPUT_ED/pre > ./DATA/errors_tus+.data
awk '{ Nu[f]=0; {Nu[f] = $2}} END { N=3; mu=0; for(i=1;i<=N;i++) {mu += Nu[i]} mu /= N; sigma=0; for(i=1;i<=N;i++) {sigma += (Nu[i]-mu)^2} sigma = sqrt(sigma/N);
print 3 " " mu " " sigma}' f=1 ./_TUS+/N=4096/w=3/OUTPUT_ED/pre f=2 ./_TUS+_1/N=4096/w=3/OUTPUT_ED/pre f=3 ./_TUS+_2/N=4096/w=3/OUTPUT_ED/pre >> ./DATA/errors_tus+.data
awk '{ Nu[f]=0; {Nu[f] = $2}} END { N=3; mu=0; for(i=1;i<=N;i++) {mu += Nu[i]} mu /= N; sigma=0; for(i=1;i<=N;i++) {sigma += (Nu[i]-mu)^2} sigma = sqrt(sigma/N);
print 4 " " mu " " sigma}' f=1 ./_TUS+/N=4096/w=4/OUTPUT_ED/pre f=2 ./_TUS+_1/N=4096/w=4/OUTPUT_ED/pre f=3 ./_TUS+_2/N=4096/w=4/OUTPUT_ED/pre >> ./DATA/errors_tus+.data
awk '{ Nu[f]=0; {Nu[f] = $2}} END { N=3; mu=0; for(i=1;i<=N;i++) {mu += Nu[i]} mu /= N; sigma=0; for(i=1;i<=N;i++) {sigma += (Nu[i]-mu)^2} sigma = sqrt(sigma/N);
print 5 " " mu " " sigma}' f=1 ./_TUS+/N=4096/w=5/OUTPUT_ED/pre f=2 ./_TUS+_1/N=4096/w=5/OUTPUT_ED/pre f=3 ./_TUS+_2/N=4096/w=5/OUTPUT_ED/pre >> ./DATA/errors_tus+.data
awk '{ Nu[f]=0; {Nu[f] = $2}} END { N=3; mu=0; for(i=1;i<=N;i++) {mu += Nu[i]} mu /= N; sigma=0; for(i=1;i<=N;i++) {sigma += (Nu[i]-mu)^2} sigma = sqrt(sigma/N);
print 6 " " mu " " sigma}' f=1 ./_TUS+/N=4096/w=6/OUTPUT_ED/pre f=2 ./_TUS+_1/N=4096/w=6/OUTPUT_ED/pre f=3 ./_TUS+_2/N=4096/w=6/OUTPUT_ED/pre >> ./DATA/errors_tus+.data
</body>
</html>