descriptioncat with bar graph
ownerGPL3
last changeMon, 12 Dec 2022 22:56:34 +0000 (23:56 +0100)
readme

barcat - concatenate texts with graph to visualize values

Visualizes relative sizes of values read from input (parameters, file(s) or STDIN). Contents are concatenated similar to cat, but numbers are reformatted and a bar graph is appended to each line.

Don't worry, barcat does not drink and divide. It can has various options for input and output (re)formatting, but remains limited to one-dimensional charts. For more complex graphing needs you'll need a larger animal like gnuplot.

Examples

Run barcat -h to get a summary of available options:

Usage
barcat [<options>] [<file>... | <numbers>]
Options

Draw a sine wave:

    seq 30 | awk '{print sin($1/10)}' | barcat

Compare file sizes (with human-readable numbers):

    du -d0 -b * | barcat -H

Same from formatted results, selecting the first numeric value:

    tree -s --noreport | barcat -H -f+

Compare media metadata, like image size or play time:

    exiftool -T -p '$megapixels ($imagesize) $filename' * | barcat

    exiftool -T -p '$duration# $avgbitrate# $filename' * | barcat --sexagesimal

    find -type f -print0 | xargs -0 -L1 \
    ffprobe -show_format -of json -v error |
    jq -r '.format|.duration+" "+.bit_rate+" "+.filename' | barcat --sex

Memory usage of user processes with long names truncated:

    ps xo rss,pid,cmd | barcat -l40

Monitor network latency from prefixed results:

    ping google.com | barcat -f'time=\K' -t

Commonly used after counting, for example users on the current server:

    users | tr ' ' '\n' | sort | uniq -c | barcat

Letter frequencies in text files:

    cat /usr/share/games/fortunes/*.u8 |
    perl -CS -nE 'say for grep length, split /\PL*/, uc' |
    sort | uniq -c | barcat

Number of HTTP requests per day:

    cat httpd/access.log | cut -d\  -f4 | cut -d: -f1 | uniq -c | barcat

Any kind of database query results, preserving returned alignment:

    echo 'SELECT sin(value * .1) FROM generate_series(0, 30) value' |
    psql -t | barcat -u

In PostgreSQL from within the client; a fancy \dt+ perhaps:

    > SELECT schemaname, relname, pg_total_relation_size(relid)
      FROM pg_statio_user_tables ORDER BY idx_blks_hit
      \g |barcat -uHf+

Same thing in SQLite (requires the sqlite3 client):

    > .once |barcat -Hf+
    > SELECT name, sum(pgsize) FROM dbstat GROUP BY 1;

Earthquakes worldwide magnitude 1+ in the last 24 hours:

    curl https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_day.csv |
    column -ts, -n | barcat -f4 -u -l80%

External datasets, like movies per year:

    curl https://github.com/prust/wikipedia-movie-data/raw/master/movies.json -L |
    jq .[].year | uniq -c | barcat

Pokémon height comparison:

    curl https://github.com/Biuni/PokemonGO-Pokedex/raw/master/pokedex.json -L |
    jq -r '.pokemon[] | [.height,.num,.name] | join(" ")' | barcat

USD/EUR exchange rate from CSV provided by the ECB:

    curl https://sdw.ecb.europa.eu/export.do \
         -Gd 'node=SEARCHRESULTS&q=EXR.D.USD.EUR.SP00.A&exportType=csv' |
    barcat -f',\K' --value-length=7

Total population history in XML from the World Bank:

    curl http://api.worldbank.org/v2/country/1W/indicator/SP.POP.TOTL |
    xmlstarlet sel -t -m '*/*' -v wb:date -o ' ' -v wb:value -n |
    barcat -f1 -H --markers=+/1e9

Population and other information for all countries:

    curl http://download.geonames.org/export/dump/countryInfo.txt |
    grep -v '^#\s' | column -ts$'\t' -n | barcat -f+2 -e -u -l150 -s

And of course various Git statistics, such commit count by year:

    git log --pretty=%ci | cut -b-4 | uniq -c | barcat

Or the top 3 most frequent authors with statistics over all:

    git shortlog -sn | barcat -L3 -s

Activity graph of the last days (substitute date -v-{}d on BSD):

    ( git log --pretty=%ci --since=30day | cut -b-10
      seq 0 30 | xargs -i date +%F -d-{}day ) |
    sort | uniq -c | awk '$1--' | barcat --spark

Sparkline graphics of simple input given as inline parameters:

    barcat -_ 3 1 4 1 5 0 9 2 4

Misusing the spark functionality to draw a lolcat line:

    seq $(tput cols) | barcat --spark --indicator=- --palette=rainbow
shortlog
2022-12-12 Mischa POSLAWSKYversion 1.10 marking stable log support master v1.10
2022-12-12 Mischa POSLAWSKYreport generic calc percentiles instead of min/max
2022-12-12 Mischa POSLAWSKYinvert percentile numbers to expected order
2022-12-12 Mischa POSLAWSKYsum calculation on demand and cached
2022-12-12 Mischa POSLAWSKYt/regress: debug output on error status
2022-12-12 Mischa POSLAWSKYignore zero values in report conditions
2022-12-12 Mischa POSLAWSKYweighted percentile interpolation
2022-12-12 Mischa POSLAWSKYmarker functions in report variables
2022-12-12 Mischa POSLAWSKYmarker positions rounded like bar lengths
2022-12-12 Mischa POSLAWSKYincrement minimum marker position
2022-12-12 Mischa POSLAWSKYdelete little joke from pod description
2022-12-12 Mischa POSLAWSKYunspecified field counts entire lines
2022-12-12 Mischa POSLAWSKYsupport count combined with trim, interval
2022-12-12 Mischa POSLAWSKYcount duplicates anchored by specified field
2022-12-12 Mischa POSLAWSKYcount option providing improved uniq -c
2022-12-04 Mischa POSLAWSKYt/regress: indicate todo in command specification
...
tags
16 months ago v1.10
17 months ago v1.09
17 months ago v1.08
4 years ago v1.07
4 years ago v1.06
4 years ago v1.05
4 years ago v1.04
4 years ago v1.03
4 years ago v1.02
4 years ago v1.01
4 years ago v1.00
4 years ago v0.10
heads
16 months ago master
4 years ago pu