bash - \r not working in awk's printf? -
bash - \r not working in awk's printf? -
found script googling, has progress bar cp, problem creates tons of lines, this:
0% [=> 0% [=> 0% [=> 0% [=> 0% [=> 0% [=> 0% [=> 0% [=> 0% [=> 0% [=> 0% [=> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==> 1% [==>
here script's code:
#!/bin/bash strace -q -ewrite cp -- `printf '%q ' $@` 2>&1 \ | awk '{ count += $nf if (count % 10 == 0) { percent = count / total_size * 100 printf "%3d%% [", percent (i=0;i<=percent;i++) printf "=" printf ">" (i=percent;i<100;i++) printf " " printf "]\r" } } end { print "" }' total_size=$(stat -c '%s' "${1}") count=0 one more thing, line ======'s long. like, when getting towards 90's, ===='s spill out on next line. how edit print 75 or lines, since default terminal 80 wide.
edit: ok realized, not work if file has space in it. [it doesn't anything, , exits right after type command]. ideas?
thank you. :)
take out printf " " before `printf "]\r":
#!/bin/bash strace -q -ewrite cp -- `printf '%q ' $@` 2>&1 \ | awk '{ count += $nf if (count % 10 == 0) { percent = count / total_size * 100 printf "%3d%% [", percent (i=0;i<=percent;i++) printf "=" printf ">" (i=percent;i<100;i++) printf "]\r" } } end { print "" }' total_size=$(stat -c '%s' "${1}") count=0 also, terminal window needs wide plenty handle characters (110 characters or more).
bash awk printf
Comments
Post a Comment