markdown linux,命令,grep

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown linux,命令,grep相关的知识,希望对你有一定的参考价值。

# using grep to filter file

``` bash
# file with regex
# you need a parameter -E to enable regex match
grep -E '4000+' -r .

# filter under current folder 
grep 'key' filename-*.xml  
grep 's.format(' -r . --include '*Test.java'

# filter with recursive 
grep 'key' --include 'filename-*.java' -r .

# filter under special folder, -r is required
grep 'sleep' -r  ./**/usermanagement

# print line around search result, -5 = -C5, 5 lines forward = -5A, 5 lines backward = -5B
cat xxx | grep -C5 'key'

# find lines with timestamp
grep '10:10:01' server.log

# find line with timestamp and company id
grep '10:10:01.*datPLT10' server.log  
also you can use multiple group  
grep 'key1' server.log | grep 'key2'  

# find wil OR operation
grep 'key1\|key2' file.log

PS: -r == -R
```

## find vs grep
grep is mainly focuse on search **content** in file  
find is mainly focuse on search **file** in system 

以上是关于markdown linux,命令,grep的主要内容,如果未能解决你的问题,请参考以下文章

linux下的find与grep命令的功能相似吗?

linux grep查询结果再过滤

linux grep命令详解

#grep ‘Linux’ filename命令查找的是啥文件?

linux 命令grep

Linux下find命令和grep命令查找文件