Hi Please help me to refine my syntax. I want to delete the excess characters from the out put below.
-bash-3.00$ top -b -n2 -d 00.20 |grep Cpu|tail -1 | awk -F ":" '{ print $2 }' | cut -d, -f1
4.4% us
now i want to delete the % and us. How wil i do that to make it just 4.4.
Thanks
can you just post the output -- or just the output of
top -b -n2 -d 00.20 |grep Cpu
I'm getting the output of 4.4% us.
I need to remove the % us to make it just 4.4 for the output.
What will i add from this syntax to delete the % and us
top -b -n2 -d 00.20 |grep Cpu|tail -1 | awk -F ":" '{ print $2 }' | cut -d, -f1
the syntax above outputs 4.4% us
Thanks
i understand your question. there is unnecessary of grep,tail,cut command
you can easily do all these things in awk itself, thats why i am asking the output
I see. But can you help me itkamaraj?
thanks
$ nawk -F"[:%]" '/Cpu/ {print $2}' test
0.0
$ cat test
top - 16:56:36 up 246 days, 11:14, 3 users, load average: 0.00, 0.00, 0.00
Tasks: 168 total, 1 running, 167 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 8306856k total, 7940744k used, 366112k free, 285136k buffers
so, in your case, it should be
top -b -n2 -d 00.20 | nawk -F"[:%]" '/Cpu/ {print $2}'
Thank you very much itkamaraj!!!
try this:
top -b -n2 -d 00.20 | grep Cpu |awk -F"[:%]" 'END{print $2}'