Reputation: 24092
How can I join this command
top -b -n 5 -d.2 | grep "Cpu" | awk 'NR==3{ print($2)}'
into only awk command (joining grep and awk into one) ?
I have tried this but with no success:
top -b -n 5 -d.2 | awk '{if( $1 == "Cpu(s):" && NR==3 ){ print($2)} }'
or
top -b -n 5 -d.2 | awk '{$1 ~ /Cpu/ && (NR==3) { print($2)}}'
Upvotes: 1
Views: 136
Reputation: 96266
awk '/Cpu/ {x++; if(x==3) { print $2}}'
Note: you can add exit
for short-circuiting.
Upvotes: 2