百度一下,各种博客,都是这么写:
linux系统中,利用grep打印匹配的上下几行
如果在只是想匹配模式的上下几行,grep可以实现。
$grep -5 ‘parttern’ inputfile //打印匹配行的前后5行
$grep -C 5 ‘parttern’ inputfile //打印匹配行的前后5行
$grep -A 5 ‘parttern’ inputfile //打印匹配行的后5行
$grep -B 5 ‘parttern’ inputfile //打印匹配行的前5行
可是我测试的时候,发现不行:
[liweizhi@bogon /]$ grep -C5 '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
[liweizhi@bogon /]$ grep -5 '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
[liweizhi@bogon /]$ grep -B 5 '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
[liweizhi@bogon /]$ grep -5 '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
[liweizhi@bogon /]$ grep -B 5 '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
[liweizhi@bogon /]$ grep -C 5 '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
-r
可以显示关键字所在行而-r
是可以的,但是只能显示符合的那一行:
[liweizhi@bogon /]$ grep -r '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.2018-06-11.0.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.2018-06-11.0.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.2018-06-11.0.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.2018-06-11.0.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.2018-06-11.0.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.2018-06-11.0.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.2018-06-11.0.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
-r
和-B
组合使用才可以后来灵机一动,是不是-r
是必备的,然后再加上-B 5
这样呢?
试了一下,果然是这样:
[liweizhi@bogon /]$ grep -r -B 1 '异常:java.lang.NullPointerException' /home/tomcat/LogsYunnanEtcApiService
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log-********【仪电9001卡操作】入参:com.uroad.etc.dto.StoreInput@2deac554[useruuid=d86a732d-2da6-11e8-add8-70106fadxxxx,orderNo=20180611000000xxxx,operationSequence=0101,instructions=803A010800A400000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,reportResults=<null>,useruuid=<null>,source=1]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
--
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log-********【仪电9001卡操作】入参:com.uroad.etc.dto.StoreInput@2fbe1a1[useruuid=d86a732d-2da6-11e8-add8-70106fadxxxx,orderNo=20180611000000xxxx,operationSequence=0101,instructions=803A010800A400000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,reportResults=<null>,useruuid=<null>,source=1]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
--
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log-********【仪电9001卡操作】入参:com.uroad.etc.dto.StoreInput@4364a874[useruuid=d86a732d-2da6-11e8-add8-70106fadxxxx,orderNo=20180611000000xxxx,operationSequence=0101,instructions=803A010800A400000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,reportResults=<null>,useruuid=<null>,source=1]
/home/tomcat/LogsYunnanEtcApiService/logbackOutFile.log:********【仪电9001卡操作】====****====异常:java.lang.NullPointerException]
--
实践出真理啊!!!
之所以学这个操作,是为了日后在命令行直接查看日志,通过grep加关键字可以直接提取出符合条件的日志记录,而且使用grep命令可以同时对多个日志文件进行搜索。如果使用notepadd++工具查看,则只能对一个文件进行查看,而且无法直接过滤出符合条件的日志记录。
原文:http://doc.okbase.net/0201zcr/archive/161440.html一、定义Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。二、所需jar包:三、简单的一个读取excel的demo1、读取文件方法/*** 读取出filePath中的所有数据信息* @param f..._poi读取excel
Faster R-CNN: Towards Real-Time Object Detection with Region Proposal NetworksShaoqing Ren, Kaiming He, Ross Girshick, Jian Sun摘要目前最先进的目标检测网络需要先用区域建议算法推测目标位置,像SPPnet[7]和Fast R-CNN[5]这些网络已经减少了检测网络的运行时间..._edgeboxes
oracle存储过程执行出现了错误,错误信息显示如下:ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytesORA-06512: 在 "SYS.DBMS_OUTPUT", line 32ORA-06512: 在 "SYS.DBMS_OUTPUT", line 97ORA-06512: 在 "SYS.DBMS_OUTPUT_oru10027
在强化学习(八)价值函数的近似表示与Deep Q-Learning中,我们讲到了Deep Q-Learning(NIPS 2013)的算法和代码,在这个算法基础上,有很多Deep Q-Learning(以下简称DQN)的改进版,今天我们来讨论DQN的第一个改进版Nature DQN(NIPS 2015)。 本章内容主要参考了ICML 2016的deep RL tutorial和Na...
同学们好!本期C++程序设计将介绍非成员函数的定义与调用、函数原型、递归调用、函数重载、作用域和编译预处理等内容。01函数的基本概念一、库函数与用户自定义函数库函数是原型说明在特定的头文件中的预定义的函数。例如,头文件中处理输入输出的函数,头文件中数学计算的函数。用户自定义函数是根据需要自己定义的函数。二、函数的参数函数在定义时定义形式参量,调用时提供实际参量。函数形参表可为空,即()或..._相互递归c++
Frame map does not exist问题:在gazebo中建图时,打开gazebo加载机器人模型,并打开rviz,在机器人模型中出现如下的错误:在终端有如下的警告:可能的原因是你的机器人模型有问题。解决方法:在机器人模型的<base_link>中加入如下部件,具体的参数自己修改:..._frame [map] does not exist
1.天线使用类型不对,GPS有对应的GPS陶瓷天线2.GPS天线增益不够或者不带增益的,可能室内搜不到卫星,特别是写字楼林立的地方。3.模块是山寨的,实质是就是一块铁
对,python使用缩进来体现代码之间的逻辑关系,对缩进的要求非常严格。Python语言通过缩进来组织代码块,这是Python的强制要求。在代码前放置空格来缩进语句即可创建语句块,语句块中的每行必须是同样的缩进量。和其它程序设计语言(如 Java、C 语言)采用大括号“{}”分隔代码块不同,Python 采用代码缩进和冒号( : )来区分代码块之间的层次。在 Python 中,对于类定义、函数定义..._python使用缩进来体现代码之间的逻辑关系。。
博客引用处(以下内容在原有博客基础上进行补充或更改,谢谢这些大牛的博客指导):nohub java -jar xx.jar &gt;/dev/null 2&gt;&amp;1 &amp;Linux 运行jar包命令如下:方式一:java -jar XXX.jar 特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出方式二:java -jar XX...
1、废话出现这个问题的原因,并不是只有一个,而是有多个原因,不懂的估计会被搞得一头雾水,下面我列举的是我遇到的几种问题和网友遇到的几种问题,但不一定是全部,也有可能有些莫名其妙的问题导致打包失败也是有可能的。2、第一种问题:签名版本的选择 根据某位大神的说法,v1和v2是两个不同版本的签名方式,两个版本最主要的区别是,v1是7.0以下系统可以安装,v2是7.0以上系统可以安装,根据我的测试,某种情..._android apk打包安卓无应用
深入理解 JavaScript 中的 replace 方法浏览:66 点评:0 发布时间: 2013-12-31 07:08:41 首先来介绍一下这个函数: replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串。 语法1 stringO_ori.replace
一、trac概念Trac是用Python写的一个基于Web的事件跟踪系统,它使用WiKi作为文档的格式,Subversion作为版本控制系统。可帮助开发人员进行源码版本管理、Bug跟踪和讨论。Debian如果你的系统是Debian则用apt-getinstalltrac命令安装即可,Trac依赖的所有软件包系统会自动安装。安装完成后,就可进行配置了。Trac可以设置成Standalone服务器,只..._搭建trac+svn