4259 links
  • Arnaud's links
  • Home
  • RSS Feed
  • Tag cloud
  • Login
search: tag:nomarkdown tag:awk — newest first
  • bash - median of column with awk - Stack Overflow

    This awk program assumes one column of numerically sorted data:

    /usr/bin/env awk

    {
    count[NR] = $1;
    }
    END {
    if (NR % 2) {
    print count[(NR + 1) / 2];
    } else {
    print (count[(NR / 2)] + count[(NR / 2) + 1]) / 2.0;
    }
    }

    Sample usage:

    sort -n data_file | awk -f median.awk

    August 2, 2016 - permalink - http://stackoverflow.com/questions/6166375/median-of-column-with-awk
    awk median nomarkdown