java查找.xx文件_Linux查找文件内容

Linux查找文件内容 - grep sed

使用vim命令查找文件内容

我们可以使用/string命令来向前(Forward)查找字符串string,按下回车后,光标就能跳到正确的地方。在这个命令中,/后的字符是我们想要查找的字符,而回车键则表明了命令的结束。

有时想要查找的内容并不仅在一处,我们可以在整个文章中进行查找:/可以继续刚才的查找操作。我们还可以使用n命令来继续刚才的查找命令。这两个命令都能达到同样的效果。

一般来说,在进行查找时总是在向前查找。我们也可以使用?命令向后(Backward)查找。N也是逆向查找命令,他可以实现立即反向查找。

如果我们想要停止这一查找,可以使用ctrl+C命令。

使用grep命令查找文件内容

Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。

常用的命令参数有:

-c:只输出匹配行的计数。

-i:不区分大小写

-n:显示匹配行及行号。

-h:查询多文件时不显示文件名。

-v:显示不包含匹配文本的所有行。

使用示例

查找以log结尾的文件中的"error"文本(忽略error大小写)匹配的行的计数。

➜ logs grep -ic 'error' *.log

error_uc4s.log:0

error_uc4sadmin.log:3758

error_ucvms.log:301

uc4s.log:0

uc4s_log.2016-10-12.log:207

......

......

......

查找文件中"ERROR"文本并显示所在行

➜ logs grep -n 'ERROR' uc4sadmin.log

1:2016-08-12 15:20:28.850 ERROR [RMI TCP Connection(2)-127.0.0.1] com.zuche.confcenter.client.manager.DefaultConfigCenterManager:108 - init confcenter fail,the reason is not found conf_center.properties file,the current project as common project and read common datasource,domain is null

2:2016-08-12 15:20:31.860 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.common.func.FuncConfirm:168 - funcClassName is not find

82:2016-08-12 15:20:37.510 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.util.InitDomainUtil:39 - remote domain = {loginImg=testImg, ucASMSURL=http://asmstest.maimaiche.com/ucasms, ucDomain=maimaiche.com, ucCRMURL=http://crmtest.maimaiche.com/uccrm, ucAdminURL=http://admintest.maimaiche.com/ucadmin, ucVMURL=http://vmstest.maimaiche.com/ucvms, ucbi=http://bitest.maimaiche.com/ucbi, ucwap=http://waptest.zhunxinche.com/ucwap, ucweb=http://webtest.zhunxinche.com/ucweb, ucRMURL=http://statictest.zhunxinche.com, env=test, zucheMapiURL=http://mapitest.zuche.com:9080, ucURMSURL=${ucURMSURL}, ucCMSURL=http://cmstest.maimaiche.com/uccms, ucRMimageURL=http://imagetest.zhunxinche.com, loginUrl=http://admintest.maimaiche.com/ucadmin/login.jsp, ucFINURL=http://fintest.maimaiche.com/ucfin, baseContextPath=http://admintest.maimaiche.com/ucadmin, ucRMjsURL=http://jstest.zhunxinche.com, ucRMcssURL=http://csstest.zhunxinche.com}

这里查出来有三条结果,“ERROR”分别在1,2还有82行。

那如果想看 82 行的上文和下文怎么办呢 ,sed 可以实现。这里打印82行到90行,p是sed的打印指令。

➜ logs sed -n '82,90p' uc4sadmin.log

2016-08-12 15:20:37.510 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.util.InitDomainUtil:39 - remote domain = {loginImg=testImg, ucASMSURL=http://asmstest.maimaiche.com/ucasms, ucDomain=maimaiche.com, ucCRMURL=http://crmtest.maimaiche.com/uccrm, ucAdminURL=http://admintest.maimaiche.com/ucadmin, ucVMURL=http://vmstest.maimaiche.com/ucvms, ucbi=http://bitest.maimaiche.com/ucbi, ucwap=http://waptest.zhunxinche.com/ucwap, ucweb=http://webtest.zhunxinche.com/ucweb, ucRMURL=http://statictest.zhunxinche.com, env=test, zucheMapiURL=http://mapitest.zuche.com:9080, ucURMSURL=${ucURMSURL}, ucCMSURL=http://cmstest.maimaiche.com/uccms, ucRMimageURL=http://imagetest.zhunxinche.com, loginUrl=http://admintest.maimaiche.com/ucadmin/login.jsp, ucFINURL=http://fintest.maimaiche.com/ucfin, baseContextPath=http://admintest.maimaiche.com/ucadmin, ucRMjsURL=http://jstest.zhunxinche.com, ucRMcssURL=http://csstest.zhunxinche.com}

2016-08-12 15:20:37.512 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.util.InitDomainUtil:42 - local domain = {mapKey=595c2643c16cefd2fdece3fb111042f7, baseContextPath=http://4sadmintest.maimaiche.com/uc4sadmin, env=development}

2016-08-12 15:23:17.624 ERROR [RMI TCP Connection(2)-127.0.0.1] com.zuche.confcenter.client.manager.DefaultConfigCenterManager:108 - init confcenter fail,the reason is not found conf_center.properties file,the current project as common project and read common datasource,domain is null

2016-08-12 15:23:18.893 ERROR [RMI TCP Connection(2)-127.0.0.1] com.uc.ucBase.common.func.FuncConfirm:168 - funcClassName is not find

java.lang.NullPointerException

at java.util.Properties$LineReader.readLine(Properties.java:434)

at java.util.Properties.load0(Properties.java:353)

at java.util.Properties.load(Properties.java:341)

at com.uc.ucBase.util.PropertiesUtil.doLoad(PropertiesUtil.java:101)

========END========

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值