![如何使用grep从当前行中减去上一行中的数字?](https://linux22.com/image/170006/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8grep%E4%BB%8E%E5%BD%93%E5%89%8D%E8%A1%8C%E4%B8%AD%E5%87%8F%E5%8E%BB%E4%B8%8A%E4%B8%80%E8%A1%8C%E4%B8%AD%E7%9A%84%E6%95%B0%E5%AD%97%EF%BC%9F.png)
mysqladmin
我使用 grep 来获取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)
答案1
附加:
| awk '{if(NR>1){print $4-last,"("$4"-"last")"} last=$4}'
输出:
26939 (265735665-265708726) 16047(265751712-265735665) 2864(265754576-265751712) 19804(265774380-265754576)
答案2
awk '/buffer_pool_pages_flushed/{curr=$(NF-1); print curr-prev; prev=curr}'