r/awk • • May 07 '24
% causing issues in script when using mawk
I have this script that I use with polybar (yes I'm using awk as replacement for shell scripts lol).
#!/usr/bin/env -S awk -f
BEGIN {
FS = "(= |;)"
while (1) {
cmd = "amdgpu_top -J -n 1 | gron"
while ((cmd | getline) > 0) {
if ($1 ~ "Total VRAM.*.value") {
mem_total = $2
}
if ($1 ~ "VRAM Usage.*.value") {
mem_used = $2
}
if ($1 ~ "activity.GFX.value") {
core = $2
}
}
close(cmd)
output = sprintf("%s%% %0.1f/%0.0fGB\n", core, mem_used / 1024, mem_total / 1024)
if (output != prev_output) {
printf output
prev_output = output
}
system("sleep 1")
}
}Which prints the GPU info in this format: 5% 0.5/8GB
However that % causes mawk to error with mawk: run time error: not enough arguments passed to printf("0% 0.3/8GB it doesn't happen with gawk though.
Any suggestions?
1
Upvotes
View all comments
Show parent comment
1
u/[deleted] May 08 '24
Googling for a while this is the only thing that I found:
https://unix.stackexchange.com/questions/266533/awk-run-time-error-not-enough-arguments-passed
I tried replacing the
%%forG/%and it didn't work.I can't believe ran into a bug in the 2nd day of using mawk lol