本文主要是介绍Linux 文件类信息统计指令(grep、awk、sort、uniq),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- grep过滤关键字
- cat 查看文件
- cat 配合awk筛选文件中某一列
- cat配合awk、sort、uniq做数据统计
- cat配合grep、awk、sort、uniq做数据统计
grep过滤关键字
cat file |grep -o word |wc -l 统计file文件中word这个关键字出现的个数cat file |grep word |wc -l 统计file文件中word这个关键字出现的行数
cat 查看文件
cat --help
cat /home/presslogs/mhp-swagger/access_log.2020-01-22.log xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 97
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 115
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 257
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 115
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 105
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 105
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 115
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 257
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 257
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 588
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/cache/removeCacheEnumDict HTTP/1.1" 200 60
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getHosParam HTTP/1.1" 200 223
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/cache/removeCacheEnumDict HTTP/1.1" 200 60
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 78
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/cache/removeCacheEnumDict HTTP/1.1" 200 60
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/cache/removeCacheEnumDict HTTP/1.1" 200 60
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getHosParam HTTP/1.1" 200 76
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getHosParam HTTP/1.1" 200 156
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/cache/removeCacheEnumDict HTTP/1.1" 200 60
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 211
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 85
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 588
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/cache/removeCacheEnumDict HTTP/1.1" 200 60
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 115
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 115
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 211
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 588
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 85
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 88
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 105
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getEnum HTTP/1.1" 200 97
xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getHosParam HTTP/1.1" 200 209
.........................
................
.......
cat 配合awk筛选文件中某一列
cat 文件名 |awk -F'按照什么切分' '显示内容'
cat /home/presslogs/mhp-swagger/access_log.2020-01-22.log |awk -F' ' '{print $7}'xxx.xxx.xxx.xx - - [22/Jan/2020:15:08:12 +0800] "POST /cfg/service/getHosParam HTTP/1.1" 200 209
按照空格切分后分成如下几部分
>xxx.xxx.xxx.xx
>-
>-
>[22/Jan/2020:15:08:12
>+0800]
>"POST
>/cfg/service/getHosParam
>HTTP/1.1"
>200
>209
cat配合awk、sort、uniq做数据统计
cat 文件名 |awk -F'按照什么切分' '显示内容'
sort 排序指令
uniq 可检查文本文件中重复出现的行列
cat /home/presslogs/mhp-swagger/access_log.2020-01-22.log |awk -F' ' '{print $7}'|sort -n|uniq -c|sort -nr
cat配合grep、awk、sort、uniq做数据统计
cat 文件名 |grep word|awk -F'按照什么切分' '显示内容'
grep 过滤
sort 排序指令
uniq 可检查文本文件中重复出现的行列
cat /home/presslogs/mhp-swagger/access_log.2020-01-22.log |grep Enum|awk -F' ' '{print $7}'|sort -n|uniq -c|sort -nr
这篇关于Linux 文件类信息统计指令(grep、awk、sort、uniq)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!