Vaibhav Soni
Vaibhav Soni

Reputation: 131

awk is not working in script running on linux

The String in file is

Wed Jan  7 03:23:03 EST 2015 Cpu(s):  3.1%us,  0.9%sy,  0.0%ni, 94.8%id,  1.2%wa,  0.0%hi,  0.1%si,  0.0%st

by using following command

echo $CPU_STATS | cut -d" " -f9| awk -F'%' '{print $1}'

Unable to get 0.9 value which have in String Please help

Upvotes: 0

Views: 94

Answers (2)

Walter A
Walter A

Reputation: 20022

When you do not want to count to 10, you can use sed:

echo $CPU_STATS | sed 's/.* \+\([\.0-9\]\+\)%sy.*/\1/'

The portion between ( and ) will be remembered and put into \1

Upvotes: 0

nu11p01n73R
nu11p01n73R

Reputation: 26667

You can write the entire statement in awk as

$ echo $CPU_STATS | awk -F"[ %]+" '{print $10}'
0.9

Upvotes: 1

Related Questions