Pages

vendredi 13 janvier 2012

manimulate row and columns with awk: mean, standard deviation

--To find the lines contain the keywork, then find the 5th column, then do the sum and average



grep "MRB 7822" parametres_gins | awk '{print $5}' | awk '{sum+=$1} END {print sum/NR}'


----To find the lines containing the keyword, then find the 5th column, then do the sqrt of all the data in this column

grep "MRB 7822" parametres_gins | awk '{print $5}' | awk '{sum+=$1*$1} END {print sqrt(sum/NR)}'


---- To find the number of rows of the selected text
grep "MRB 7822" parametres_gins | awk 'END {print NR}'


---- To find the standard deviation of data which are in the 3rd column of a data array in a file :
awk  ‘{sum+=$3; sumsq+=$3*$3 } END {print sqrt(sumsq/NR – (sum/NR)^2)}’    data_file


---- to substract two columns of data which are from two files:
cat file1   | awk '{column1=$which_column_in_file1; getline <"file2"; print column1 - $which_column_in_file2}'   

Aucun commentaire:

Enregistrer un commentaire