Array arithmetic bash shell -
I have a number of files ( nTotal ), with a column of each length < Strong> L Float numbers, I want to enter all these files in line I_th and add them at the end. Calculate my average and standard deviation I had read each file before, then I try to add this array to an array which gives me a syntax error: (standard_in) 2: syntax error . I hope that now all the files in the suma [i] contain the amount of all entries on the line I_th, after which I think the average edit for loops changed Has been suggested as it has been.
((n = 1; n & lt; $ nTotal; n ++)) IFS = $ '\ N' arr1 = ($ (. / .out file name | sed ' S (/ i = 1; i & lt; $ L; i ++)), for [i] = `resonance '$ {amount [i]} - $ {arr1} [I]} "| | Done for BC '((i = 1; i & lt; $ L; i ++)) or = $ (echo -1 * $ {sum [i]} | bc) aveSum = $ (echo $ ya / $ N Total BC-L) done
Edit: ./a.out produces file with a column of float numbers.
However, I read again data files and store them in the array (to make standard deviation) (I'm sure this is not the smartest way to do this. , But I could not think of anything else.) I could not even use standard deviation:
for ((i = 1; i
Here I get a zero for the val [i] elements, I can not understand what is wrong. If you guide me to this problem I really appreciate it.
Bash can not be easy at all Especially because it does not apply to non-integer arithmetic, I use awk:
awk '{n [FNR] ++; delta = $ 1 - mean [fn R]; Meaning [FNR] + = Delta / N [FNR]; M2 [FNR] + = Delta * ($ 1 - mean [FNR]); } END {for (i = 1; i in n; ++ i) print mean [i], sqrt (m2 [i] / (n [i] -1); } 'File1 file2 ...
Mathematics is taken directly from the famous program, the program assumes that all files are exactly L
lines, but if there are few or more , Then the missing data will be ignored; You want to test a better validity in a special case that there are several lines in a single file, the standard deviation calculation will be trapped in a divider-zero-zero; In a reading, it does not matter because the correct data will be printed in advance, but you would also like to fix it.
This program uses some weird features: First, the arrays are automatically started in (and lazy) 0 (if used as number); Second, FNR
is the row number in the current file. ( NR
is the line number as an input, but in this case FNR
is more useful.)
Comments
Post a Comment