Using Bash one-liners for stats

Bash Out Some Stats

© Photo by Carlos Muza on Unsplash

© Photo by Carlos Muza on Unsplash

Author(s):

With just one line of Bash you can use tools like AWK and gnuplot to quickly analyze and plot your data.

Typically when I'm looking to do some data analysis, I'll import the data files into Pandas DataFrames or an SQL database. During a recent project, I was happily surprised to learn that I could do a lot of basic statistics with only one line of Bash code.

For simple applications, Bash tools such as sort and bc (the arbitrary precision calculator) can be used to find maximums, minimums, averages, and sums from arrays or columns of data (Listing 1).

For CSV data files, a single line of Bash that combines AWK [1] and gnuplot [2] can be used to view statistics or graph a column of data (Figure 1).

[...]