LoginSignup
5
4

More than 5 years have passed since last update.

行の数値の平均をとる

Last updated at Posted at 2014-12-25
NF>1 {
  i=1;
  sum=0;
  while(i <= NF) {
    sum += $i;
    i++;
  }
  print sum/NF;
}

test

> echo '1 2 3 4 5' | awk 'NF>1 {i=1;sum=0; while(i <= NF) {sum += $i; i++;} print sum/NF;}'
3

(12/27編集) heliac2000さんのコメントを適用

5
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4