Command-Line
如何使用grep從目前行中減去前一行中的數字?
我使用 grep 來獲取
mysqladmin
as的輸出sudo mysqladmin ext -i10 | grep 'buffer_pool_pages_flushed'
並且輸出是連續的(每 10 秒)為
| Innodb_buffer_pool_pages_flushed | 265708726 | | Innodb_buffer_pool_pages_flushed | 265735665 | | Innodb_buffer_pool_pages_flushed | 265751712 | | Innodb_buffer_pool_pages_flushed | 265754576 | | Innodb_buffer_pool_pages_flushed | 265774380 |
如何調整
grep
命令以輸出第二列中連續數字之間的差異,例如26939 (265735665-265708726) 16047 (265751712-265735665) 2864 (265754576-265751712) 19804 (265774380-265754576)
附加:
| awk '{if(NR>1){print $4-last,"("$4"-"last")"} last=$4}'
輸出:
26939 (265735665-265708726) 16047 (265751712-265735665) 2864 (265754576-265751712) 19804 (265774380-265754576)
awk '/buffer_pool_pages_flushed/{curr=$(NF-1); print curr-prev; prev=curr}'