0

I found this command in this discussion.

According to the command

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

I got the result is such as 2.9%.

I would like to remove % when output. Which part is printing % ?

Community
  • 1
  • 1
pico
  • 247
  • 3
  • 9
  • 20

1 Answers1

1

Have you tried

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

I've removed the last %% in the printf.

fredmaggiowski
  • 2,232
  • 3
  • 25
  • 44