Datamash Examples

May 12, 2025


Sum of a column or multiple columns.

$ cat data
9   6   9   4
2   6   8   0
8   3   8   3
9   6   7   5
7   3   5   8

If the file or input is tab separated, then use

cat data | datamash sum 1
cat data | datamash sum 1,3
cat data | datamash sum 1-2,3

If the file or input is space separated, then use -t " ".

cat data | datamash -t " " sum 1
cat data | datamash -t " " sum 1,3

If the file or input has a header row, then use --headers.

$ cat data
A   B   C   D
9   6   9   4
2   6   8   0
8   3   8   3
9   6   7   5
7   3   5   8
cat data | datamash --headers sum 1,2


Average (mean) of a column or multiple columns.

$ cat data
9   6   9   4
2   6   8   0
8   3   8   3
9   6   7   5
7   3   5   8

If the file or input is tab separated, then use

cat data | datamash mean 1
cat data | datamash mean 1,3
cat data | datamash mean 1-2,3

If the file or input is space separated, then use -t " ".

cat data | datamash -t " " mean 1
cat data | datamash -t " " mean 1,3

If the file or input has a header row, then use --headers.

$ cat data
A   B   C   D
9   6   9   4
2   6   8   0
8   3   8   3
9   6   7   5
7   3   5   8
cat data | datamash --headers mean 1,2


Transpose rows and columns of a file or input.

$ cat data
11  41  19
67  97  23

If the file or input is tab separated, then use

datamash transpose < data

If the file or input is space separated, then use -t " ".

datamash transpose -t " " < data

If the file or input is , separated, then use -t ",".

datamash transpose -t "," < data