Not sure how to do this with grep
, but awk
can easily do it. For example:
# Simple script to generate completion strings
i=0
while :; do
echo $((i+=4))% done
sleep $((RANDOM%3))
done |
# Look for '%' and print out the line with a carriage-return prepended
awk '/%/ { printf "\r%s Done", $1 }'
Copy paste the above to a bash
command line to test.
You might also consider piping the progress-percent to zenity
. For example:
# Simple script to generate completion strings
i=0
while :; do
echo $((i+=4))% done
sleep $((RANDOM%3))
done |
# This assumes that the progress strings are formatted as above
grep --line-buffered -o '^[^%]*' |
# zenity quits when 100 arrives on stdin
zenity --progress --auto-close --no-cancel