Created
March 26, 2024 20:03
-
-
Save alifeee/a6f14aad9caed6b8a861df0e2850aa10 to your computer and use it in GitHub Desktop.
Simple bar chart generation with bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# make bar chart from $prog, $total, $n_seg as $1 $2 $3 | |
# example: | |
# > ./bar.sh 25 100 12 | |
# ███░░░░░░░░░ | |
awk -v prog=$1 -v TOTAL=$2 -v TOTSEG=$3 'BEGIN { | |
frac = prog / TOTAL; | |
segs = frac * TOTSEG; | |
segs_int = int(sprintf("%.0f", segs)); | |
for (s=0; s<segs_int; s++) { | |
printf "%s", "█"; | |
} | |
for (s=0; s<(TOTSEG - segs_int); s++) { | |
printf "%s", "░"; | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment