Here is a way to print awk on STDERR every second. You should simply add:
- When myprocess is finished, create the file / tmp / SOMETHING
- Awk has a test: it exits when / tmp / SOMETHING appears
Part of a loop (without completion test ... so there is an "endless loop" to CTRL-C):
ping 127.0.0.1 | awk ' BEGIN{cmd="date +%s"; cmd|getline startup ; close (cmd) } /bytes from/ { cmd | getline D ; close (cmd) ; print D-startup | "cat >&2" }'
now you just need to use "printf" and the ansi escape sequence to print without a new line, try ansi-escape to return to the beginning of the number and reset the output (all descriptors) by calling the system:
ping 127.0.0.1 | awk -v getback4char="$(printf '\033[4D')" ' BEGIN{cmd="date +%s"; cmd|getline startup ; close (cmd) ; printf "Elapsed time: ";} /bytes from/ { cmd | getline D ; close (cmd) ; printf "%4d%s" ,(D-startup) , getback4char | "cat >&2" system("") }'
note: this is compatible with all versions of awk that I know, even ANCIENT (i.e. not only gawk / nawk, but also venerable awk.)
source share