Skip to content

Instantly share code, notes, and snippets.

@pbatey
Created June 21, 2019 15:23
Show Gist options
  • Save pbatey/25c55b8695a262969fe91d59140f492b to your computer and use it in GitHub Desktop.
Save pbatey/25c55b8695a262969fe91d59140f492b to your computer and use it in GitHub Desktop.
Bash script to display progress (to stderr) by counting lines from stdin.
#!/bin/bash
#
# Displays progress (to stderr) by counting lines from stdin.
#
# Usage: <command> | progress.sh <expected-line-count> > <file>
#
total=$(( ${1:-0} ))
number=0
while read line; do
number=$(( number+1 ))
if [ $total -gt 0 ]; then
percent=$(( number*100/total ))
>&2 echo -en " $percent%\r"
fi
echo $line
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment