Forrest logo
back to the echo tool

datamash:tldr:c136a

datamash: Get the mean of a single column of float numbers (floats must use "," and not ".").
$ echo -e '1.0\n2.5\n3.1\n4.3\n5.6\n5.7' | tr '.' ',' | datamash mean 1
try on your machine

The command echo -e '1.0\n2.5\n3.1\n4.3\n5.6\n5.7' | tr '.' ',' | datamash mean 1 performs the following actions:

  1. echo -e '1.0\n2.5\n3.1\n4.3\n5.6\n5.7': This prints the given string '1.0\n2.5\n3.1\n4.3\n5.6\n5.7' to the command line. The -e option enables the interpretation of escape sequences, so \n creates line breaks.

  2. |: The pipe symbol | is used to redirect the output of the previous command (echo) to the input of the next command (tr).

  3. tr '.' ',': This command uses the tr command to replace any occurrence of . with ,. It is used to convert the decimal point from . to ,.

  4. |: Another pipe symbol is used to redirect the output of the previous command (tr) to the input of the next command (datamash).

  5. datamash mean 1: This command uses datamash to calculate the mean (average) of the numbers provided in the input. mean is the function to calculate the mean, and 1 specifies that the calculation should be performed on the first column of the input.

Overall, this command takes a string of numbers separated by newlines, replaces the decimal points with commas, and then calculates the mean of the numbers in the first column.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the echo tool