如何从 shell 命令的输出中删除 %

How to remove % from output in shell command

我在 this discussion 中找到了这个命令。

根据命令

top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split(, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }'

我得到的结果是2.9%。

我想在输出时删除 % 。哪个部分正在打印 % ?

你试过了吗

top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split(, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f\n", prefix, 100 - v }'

我删除了 printf 中的最后一个 %%