You are not logged in.
I'm trying to run
awk '{print $1*1e-6 " W"}' /sys/class/power_supply/BAT0/power_now
but with "watch". For example, something like:
watch -n3 -t awk '{print $1*1e-6 " W"}' /sys/class/power_supply/BAT0/power_now
The above doesn't work though. I've tried wrapping the "awk" part in quotes and escaping the inner quotes (etc), but it still doesn't work.
How can I get the above to work (so I can watch the output of awk '{print $1*1e-6 " W"}' /sys/class/power_supply/BAT0/power_now)?
Last edited by andyturfer (2024-01-22 02:15:17)
Offline
You'll need to escape the dollar sign as well. This works:
watch -n1 -t 'awk "{print \$1*1e-6 \" W\"}" /sys/class/power_supply/BAT0/power_now'
Of course, "watch" has always struck me as silly. A loop is simpler and cleaner:
while :; do awk '{print $1*1e-6 " W"}' /sys/class/power_supply/BAT0/power_now; sleep 3; done
(you could add a clear screen ansi sequence to the print if you really wanted that visual effect).
EDIT: note, the -x flag to watch would probably also help ... but the existence of that flag makes the whole "watch" program that much more silly (i.e., that "-x" is not what it's doing by default is pretty ridiculous).
Last edited by Trilby (2024-01-22 03:03:21)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Nice one - thanks!
Offline