如何使用grep从当前行中减去上一行中的数字?

如何使用grep从当前行中减去上一行中的数字?

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}'

相关内容