计算与平面文件的差异
我有一个文本文件,最后两行看起来像这样...
Uptime: 822832 Threads: 32 Questions: 13591705 Slow queries: 722 Opens: 81551 Flush tables: 59 Open tables: 64 Queries per second avg: 16.518
Uptime: 822893 Threads: 31 Questions: 13592768 Slow queries: 732 Opens: 81551 Flush tables: 59 Open tables: 64 Queries per second avg: 16.618
如何找到每个参数的两个值之间的差异? 预期输出是:
61 -1 1063 10 0 0 0 0.1
换句话说,我想从早期的正常运行时间中扣除当前的正常运行时间值。 找出线索和问题之间的区别等等。
此练习的目的是观察此文件并在差异太大时提醒用户。例如,如果慢查询超过 500 或“Questions”参数太低(<100)
(这是 MySQL 状态,但与之无关,因此 mysql 标签不适用)
I have a text file and the last 2 lines look like this...
Uptime: 822832 Threads: 32 Questions: 13591705 Slow queries: 722 Opens: 81551 Flush tables: 59 Open tables: 64 Queries per second avg: 16.518
Uptime: 822893 Threads: 31 Questions: 13592768 Slow queries: 732 Opens: 81551 Flush tables: 59 Open tables: 64 Queries per second avg: 16.618
How do I find the difference between the two values of each parameter?
The expected output is:
61 -1 1063 10 0 0 0 0.1
In other words I will like to deduct the current uptime value from the earlier uptime.
Find the difference between the threads and Questions and so on.
The purpose of this exercise is to watch this file and alert the user when the difference is too high. For e.g. if the slow queries are more than 500 or the "Questions" parameter is too low (<100)
(It is the MySQL status but has nothing to do with it, so mysql tag does not apply)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与 Ghostdog74 的(原始)答案略有不同:
Just a slight variation on ghostdog74's (original) answer:
这是一种方法。 tail 用于获取最后两行,如果您有一个大文件,则在效率方面特别有用。
输出
here's one way. tail is used to get the last 2 lines, especially useful in terms of efficiency if you have a big file.
output
呆呆地:
gawk: