bash I/O redirection - how to append to stderr
1
vote
1
answer
84
views
I have a script that loops over some big collection of data and performs some lenghty operations. Then i need to
sort | uniq -c
its output. So to let it know that its alive, I print a dot every N items on stderr (very primitive pseudo progress-bar), so it looks pretty much like this:
for i in {1..100}; do
[[ $(( (i+=1) % 10)) -eq 0 ]] && echo -n "." >&2
shuf -i 1-10 -n1
sleep 0.1
done | sort | uniq -c
and the output:
.......... 9 1
10 10
8 2
14 3
13 4
9 5
11 6
8 7
8 8
10 9
the "progress bar" messes up the output a little - so i was wondering:
* is there an easy way to add a nweline to that stderr before flushing that stdout? (probably echo >&2
is all I need)
* or remove it ?
of course in reeality i dont know wow many items there are (at least not out-of-the box). So i was wondering if this can be acieved by some stream redirection
Asked by murison
(163 rep)
Jun 14, 2021, 03:44 PM
Last activity: Jun 14, 2021, 04:12 PM
Last activity: Jun 14, 2021, 04:12 PM