Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a tab separated data file (or another separator), how would you compute the mean of a column?

Too bad that there are no simple binaries that performs simple mathematical operations over those kind of files.

share|improve this question
up vote 7 down vote accepted
awk -F'\t' '{ sum += $1 } END { print sum / NR }'

Here $1 is the first \tab-separated column.

share|improve this answer

If you have R installed you can also use:

Rscript -e "(mean(read.table(\"\")))"

You can also change the function (mean) to other statistical functions, say:

Rscript -e "(mean(read.table(\"\")))"
Rscript -e "(sd(read.table(\"\")))"
Rscript -e "(summary(read.table(\"\")))"

If you want to specify the column, say, use column 3, then you use the notation [,3]

Rscript -e "(sum(read.table(\"file\")[,3]))"


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.