Using Bash one-liners for stats

Bash Out Some Stats

© Photo by Carlos Muza on Unsplash

© Photo by Carlos Muza on Unsplash

Article from Issue 294/2025
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).

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Gnuplot

    Use Gnuplot with command-line utilities.

  • Open Data

    A lot of COVID-19 data is available through online REST APIs. With a little ingenuity and some open source tools, you can extract and analyze the data yourself.

  • Tutorials – Shell Math

    While Bash is not the most advanced environment for doing and visualizing math, its power will surprise you. Learn how to calculate and display your results with shell scripts.

  • Embedding Scripts in Bash

    Solve Bash blind spots by embedding other scripting languages into your Bash scripts to get the features you need. Pete shows you solutions for floating-point math, charting, GUIs, and hardware integration.

  • Stat-like Tools for Admins

    ASCII tools can be life savers when they provide the only access you have to a misbehaving server. However, once you're on the node what do you do? In this article, we look at stat-like tools: vmstat, dstat, and mpstat.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News