egrep 等同于 grep -E 。它会以扩展的正则表达式的模式来解释模式。
多条件导出
jps -l|grep -E 'game|cross'
匹配有no 同时有Template关键词的行
grep 'no ' /data/log/game/1/game.2017-05-04-10.log |grep Template
resuilt>
26000:2017-05-04 10:21:38.605 ERROR [game-logout-1][ResourceManager] - no BornPositionTemplate: 1
26001:2017-05-04 10:21:38.606 ERROR [game-logout-1][ResourceManager] - no AttributeRelationTemplate: velocity
33172:2017-05-04 10:29:25.856 ERROR [game-logout-3][ResourceManager] - no AttributeRelationTemplate: velocity
34497:2017-05-04 10:31:37.857 ERROR [game-logout-1][ResourceManager] - no AttributeRelationTemplate: velocity
1.找出字符串里的数字
"abc34325sad" --->34325
Matcher m=Pattern.compile("\\d+").matcher("于修订版 19842"); while(m.find()){ System.out.print(m.group()+""); }
result:
19842
grep 支持正则表达式搜索
grep '[0-9]\{4,\}' /tmp/a.txt 搜索有至少4个连续数字的行
grep 'RoleCache长度=[0-9]\{4,\}' /tmp/a.txt 搜索有至少4个连续数字的行
搜索中文
双引号中文字懒惰匹配
".*[\u4e00-\u9fa5]+.*?"
单引号中文字懒惰匹配
'.*[\u4e00-\u9fa5]+.*?'
grep 'num=7[0-9]\{4,\}' /data/log/logger/logger.2014-11-*
搜索出带有num=7前缀的后面连续4个数字的日志
[root@VM_252_18_centos logger]# grep 'num=6[0-9]\{4,\}' /data/log/logger/logger.2014-11-* /data/log/logger/logger.2014-11-18-17.log:2014-11-18 17:34:19.251 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=64536 /data/log/logger/logger.2014-11-18-17.log:2014-11-18 17:52:57.823 INFO [gameScheduler-1][LoggerManager.java:54] - 文件处理完毕 num=64536 failed=1,exec=1118572.2 ms interval=17.332531 ms /data/log/logger/logger.2014-11-18-19.log:2014-11-18 19:17:33.364 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=65590 /data/log/logger/logger.2014-11-18-19.log:2014-11-18 19:36:35.594 INFO [gameScheduler-1][LoggerManager.java:54] - 文件处理完毕 num=65590 failed=1,exec=1142230.5 ms interval=17.414705 ms /data/log/logger/logger.2014-11-18-19.log:2014-11-18 19:36:35.683 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=68409 /data/log/logger/logger.2014-11-18-19.log:2014-11-18 19:56:18.685 INFO [gameScheduler-1][LoggerManager.java:54] - 文件处理完毕 num=68409 failed=0,exec=1183002.0 ms interval=17.293076 ms /data/log/logger/logger.2014-11-18-19.log:2014-11-18 19:56:18.784 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=62452 /data/log/logger/logger.2014-11-18-22.log:2014-11-18 22:04:44.547 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=62452 /data/log/logger/logger.2014-11-18-22.log:2014-11-18 22:22:33.249 INFO [gameScheduler-1][LoggerManager.java:58] - 文件处理完毕 num=62452 failed=0,exec=1068702.4 ms interval=17.112381 ms /data/log/logger/logger.2014-11-18-23.log:2014-11-18 23:30:35.724 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=68445 /data/log/logger/logger.2014-11-18-23.log:2014-11-18 23:49:59.506 INFO [gameScheduler-1][LoggerManager.java:58] - 文件处理完毕 num=68445 failed=0,exec=1163782.8 ms interval=17.003181 ms /data/log/logger/logger.2014-11-19-00.log:2014-11-19 00:52:54.803 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=69359 /data/log/logger/logger.2014-11-19-01.log:2014-11-19 01:12:45.359 INFO [gameScheduler-1][LoggerManager.java:58] - 文件处理完毕 num=69359 failed=0,exec=1190555.5 ms interval=17.16512 ms /data/log/logger/logger.2014-11-19-01.log:2014-11-19 01:23:30.906 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=62934 /data/log/logger/logger.2014-11-19-01.log:2014-11-19 01:41:20.206 INFO [gameScheduler-1][LoggerManager.java:58] - 文件处理完毕 num=62934 failed=0,exec=1069300.1 ms interval=16.990818 ms /data/log/logger/logger.2014-11-19-01.log:2014-11-19 01:41:20.349 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=63699 /data/log/logger/logger.2014-11-19-01.log:2014-11-19 01:59:39.349 INFO [gameScheduler-1][LoggerManager.java:58] - 文件处理完毕 num=63699 failed=0,exec=1099000.5 ms interval=17.253025 ms /data/log/logger/logger.2014-11-19-03.log:2014-11-19 03:50:56.145 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=65128 /data/log/logger/logger.2014-11-19-04.log:2014-11-19 04:09:27.597 INFO [gameScheduler-1][LoggerManager.java:58] - 文件处理完毕 num=65128 failed=0,exec=1111451.9 ms interval=17.065653 ms /data/log/logger/logger.2014-11-19-04.log:2014-11-19 04:15:24.328 INFO [gameScheduler-1][LoggerManager.java:45] - 文件处理开始 num=65509 /data/log/logger/logger.2014-11-19-04.log:2014-11-19 04:34:03.212 INFO [gameScheduler-1][LoggerManager.java:58] - 文件处理完毕 num=65509 failed=0,exec=1118884.2 ms interval=17.079855 ms
获取iparam_1之前的,包括iparam_1的字符:
game.2015-06-10-15-44.log:http://183.61.46.225/report.php?iappid=1102562958&idomain=1&ioptype=1001&iactionid=0&iworldid=1027&vuin=29265C44A9B3C6B676AFE8A8FFF25E5F&iuserip=1999718489&ieventTime=1433922159&iparam_1=72&iparam_2=90&vparam_1=5577ea670000038a&vparam_2=-APPDJ35338-20150610-1542395087&iparam_3=1&iparam_4=0
.+&iparam_1
======================
获取夹在两个特殊符号的中间是数字的
iparam_1=95&iparam_2
iparam_1=\d+&iparam_2
========================
把10~14号的充值日志提取出来重新上报,查询多文件时不显示文件名
grep -h ioptype=1001 /data/backup/tencent/*/*/*.2015-06-1[0-4]*.log > /data/stat/tencent/charge.log
============================
/data/backup/tencent/game/8036/game.2015-06-15-16-44.log.gz:
/data/backup/tencent/.+log.gz:
提取/data/backup/tencent/和log.gz:的值
==================================
把=后面的都删除
a=啊阿呵吖嗄腌锕錒;
be=萡;
替换
查找目标 =.+
替换为< 空行>
选中所有是英文的
[a-z]+
buffalo 水牛
bull 公牛
cow 母牛
=====================================
grep 'message interval=[0-9]\{4,\}.' /tmp/game.log
获取高延迟的消息
======================================
中文字符查找
^[\u4E00-\u9FFF]+$