I have a script on a Linux machine with a fancy pv piped to a second pv that count a subset of the outputted lines.
Here's the script:
max=1000
for (( i=0; i<max; i++ )); do
[[ $(shuf -i 1-100 -n 1) -lt 20 ]] && echo REMOVE || echo LEAVE
done | pv -F "%N %b / $(numfmt --to=si $max) %t %p %e" -c -N 'Lookups' -l -s $max \
| grep --line-buffered '^REMOVE' \
| pv -F "%N %b / $(numfmt --to=si $max)" -c -N 'Deletes' -l -s $max \
>/dev/null
stty sane
what I would expect is that the first pv always shows first, and the second always second.
Like this example output:
$ ./fancy_pv.sh
Lookups: 1.00k / 1.0K 0:00:03 [===============================================================================================================================================================================================================================================================================================================================================================>] 100%
Deletes: 189 / 1.0K
But that's not the case, sometimes they swap positions and I see something like this:
$ ./fancy_pv.sh
Deletes: 199 / 1.0K
Lookups: 1.00k / 1.0K 0:00:03 [===============================================================================================================================================================================================================================================================================================================================================================>] 100%
And sometimes I also see something like this:
$ ./fancy_pv.sh
Lookups: 321 / 1.0K 0:00:01 [===============================================================================================================> ] 32% ETA 0:00:02
Deletes: 198 / 1.0K
Lookups: 1.00k / 1.0K 0:00:03 [===============================================================================================================================================================================================================================================================================================================================================================>] 100%
I know it must be because of the way pv deletes the line and redraws it, but is there anything I can do to prevent it from messing with the order?
stty sane is there to sanitize the prompt because sometimes pv leaves the terminal unusable.
Thanks