Linux Shell:检测CSV日志文件上的状态更改 [英] Linux shell: Detecting state changes on a CSV log file

查看:45
本文介绍了Linux Shell:检测CSV日志文件上的状态更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我自动生成的日志文件(持续一分钟检查我的互联网线路):

This is my automatically-generated log file (continuous one-minute checking of my internet line) :

$ cat log.csv

2018-04-27,23:37,OK
2018-04-27,23:38,OK
2018-04-27,23:39,OK
2018-04-27,23:40,ERROR
2018-04-27,23:41,ERROR
2018-04-27,23:42,OK
2018-04-27,23:43,OK
2018-04-27,23:44,OK
2018-04-27,23:45,OK

我试图通过编写一些依赖于第三字段(行状态:OK/ERROR)状态并删除连续值(某种shell脚本)的解释方法来编写脚本,以使其阅读起来更加舒适仅显示互联网线路的初始和状态更改,将上面的日志转换为:

I am trying to make it more confortable for reading by scripting some interpretation method that depends on the 3rd field (line state: OK/ERROR) state and removes consecutive values, some sort of shell script that only shows the initial and state change for the internet line, transforming the above log into:

2018-04-27,23:37,OK
2018-04-27,23:40,ERROR
2018-04-27,23:42,OK

那将意味着:

2018-04-27,23:37,Entered Status OK
2018-04-27,23:40,Entered Status ERROR
2018-04-27,23:42,Entered Status OK

可以看出,仅保留状态更改将使日志的显示更短,更容易.

As can be seen, leaving only the state changes makes the log's display shorter and easier to read.

假设日志文件可能很长(考虑数分钟的一分钟日志记录),那么什么是在Linux shell上编写此解释"脚本的合适(有效)方法?

Assuming the log file could be very long (consider months of one-minute logging), what could be a proper (efficient) method to script this "interpretation" on a Linux shell?

我知道迭代不是

I know that iterations are not considered a very good idea on shells, so I was thinking about AWK, but I am not very experienced on it.
Loops solutions could be better than nothing, of course.

其他数据:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆