I am trying to catch some data from iostat output:

# iostat  -m

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           9.92    0.00   14.17    0.01    0.00   75.90

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
sda               6.08         0.00         0.04       2533     261072
dm-0              1.12         0.00         0.00       1290      30622
dm-1              0.00         0.00         0.00          1          0
dm-2              1.22         0.00         0.00          0      33735
dm-3              7.22         0.00         0.03       1213     196713

How can I match the "0.00" value? Numbers aren't separated by a tab or a constant number of spaces. Also the value can be 3 digits 0.00 or 4 digits 45.00, etc.

Any idea how to match it using bash?

有帮助吗?

解决方案

Try this, using awk:

iostat | awk 'NR==3 { print $5 }'

NR==3 will operate on the third line, and $5 prints column 5. Verify that the proper column is being selected by playing around with the number, i.e. using your output and print $4 should yield 0.01.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top