Linux 指令日志分析 (一)
发布于: 刚刚
在 Linux 系统进行日志定位需要从大量的日志中搜索有效信息,本文就日常使用到的grep
、awk
和sort
进行日志分析。
假设存在如下4.txt
文件
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:0
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:10
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:100
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:101
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:102
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:111
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:112
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:104
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:108
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:105
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:106
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:1
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:107
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:10b
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:10c
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:10d
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:10e
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:10f
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:11
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:110
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:113
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:103
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:114
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:115
2019-1010-1920 192.345.23.3 Report 70b:a8dd:6f:116
复制代码
提取第三列信息
cat 4.txt | awk '{print $4}'
复制代码
如果需要对提取的信息排序则执行
cat 4.txt | awk '{print $4}' | sort
复制代码
会得到如下信息
70b:a8dd:6f:0
70b:a8dd:6f:1
70b:a8dd:6f:10
70b:a8dd:6f:100
70b:a8dd:6f:101
70b:a8dd:6f:102
70b:a8dd:6f:103
70b:a8dd:6f:104
70b:a8dd:6f:105
70b:a8dd:6f:106
70b:a8dd:6f:107
70b:a8dd:6f:108
70b:a8dd:6f:10b
70b:a8dd:6f:10c
70b:a8dd:6f:10d
70b:a8dd:6f:10e
70b:a8dd:6f:10f
70b:a8dd:6f:11
70b:a8dd:6f:110
70b:a8dd:6f:111
70b:a8dd:6f:112
70b:a8dd:6f:113
70b:a8dd:6f:114
70b:a8dd:6f:115
70b:a8dd:6f:116
复制代码
划线
评论
复制
发布于: 刚刚阅读数: 2
版权声明: 本文为 InfoQ 作者【正向成长】的原创文章。
原文链接:【http://xie.infoq.cn/article/a9d292dca9718b23e021502dd】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
正向成长
关注
正向成长 2018.08.06 加入
想要坚定地做大规模数据处理(流数据方向),希望结合结合批处理的传统处理方式,以及之后流批混合处理方向进行学习和记录。
评论