ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

shell中级-grep

2022-01-13 20:59:45  阅读:221  来源: 互联网

标签:中级 shell grep REGISTER sip CSeq conf root


基础正则:

^ 以什么开头  

$ 以什么结尾

 ^$ 空行    

.  任意一个字符     \.为转义“.”     \n  回车     \t   tab建

*   连续出现  

.*  所有

grep --color "^.*REGISTER" /archive/log/tracesbc/tracesbc_sip/tracesbc_sip_1640047578 -n

56277:Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, PRACK, REFER, REGISTER, SUBSCRIBE, UPDATE, PUBLISH

56305:Allow: ACK, BYE, CANCEL, INFO, INVITE, MESSAGE, NOTIFY, OPTIONS, PRACK, REFER, REGISTER, SUBSCRIBE, UPDATE, PUBLISH

56323:REGISTER sip:219.232.39.226 SIP/2.0

56329:CSeq: 1 REGISTER

56343:CSeq: 1 REGISTER

56354:REGISTER sip:219.232.39.226 SIP/2.0

56357:CSeq: 1 REGISTER

56374:CSeq: 1 REGISTER

56391:CSeq: 1 REGISTER

56405:REGISTER sip:219.232.39.226 SIP/2.0

56411:CSeq: 2 REGISTER

56426:CSeq: 2 REGISTER

56437:REGISTER sip:219.232.39.226 SIP/2.0

56440:CSeq: 2 REGISTER

56457:CSeq: 2 REGISTER

56474:CSeq: 2 REGISTER

56502:REGISTER sip:219.232.39.226 SIP/2.0

56508:CSeq: 1 REGISTER

56522:CSeq: 1 REGISTER

56533:REGISTER sip:219.232.39.226 SIP/2.0

56536:CSeq: 1 REGISTER

56553:CSeq: 1 REGISTER

56570:CSeq: 1 REGISTER

56584:REGISTER sip:219.232.39.226 SIP/2.0

56590:CSeq: 2 REGISTER

56605:CSeq: 2 REGISTER

56616:REGISTER sip:219.232.39.226 SIP/2.0

56619:CSeq: 2 REGISTER

56636:CSeq: 2 REGISTER

56653:CSeq: 2 REGISTER

匹配数字

 [0-9]       

匹配小写[a-z]      

匹配大小写

grep '[a-Z0-9]’ redis.conf  

grep  -i '[a-z0-9]’ redis.conf  

取反,例子:取除a、b、c的内容

[^abc]

扩展正则:+ | () {} ?

每一行都有$结尾

cat -A redis.conf

# Set aof rewrite child process to cpu affinity 8,9,10,11:$

# aof_rewrite_cpulist 8-11$

#$

# Set bgsave child process to cpu affinity 1,10,11$

# bgsave_cpulist 1,10-11$

$

# In some cases redis will emit warnings and even refuse to start if it detects$

# that the system is in bad state, it is possible to suppress these warnings$

# by setting the following config which takes a space delimited list of warnings$

# to suppress$

#$

# ignore-warnings ARM64-COW-BUG$

[root@demo1 conf]# sed  -i 's/6381/6882/g' myredis6382.conf |more

[root@demo1 conf]# cat -A redis.conf |more

# Redis configuration file example.$

#$

# Note that in order to read the configuration file, Redis must be$

# started with the file path as first argument:$

#$

# ./redis-server /path/to/redis.conf$

$

# Note on units: when memory size is needed, it is possible to specify$

# it in the usual form of 1k 5GB 4M and so forth:$

#$

# 1k => 1000 bytes$

# 1kb => 1024 bytes$

# 1m => 1000000 bytes$

# 1mb => 1024*1024 bytes$

# 1g => 1000000000 bytes$

# 1gb => 1024*1024*1024 bytes$

查找root在一个文件中,并标记颜色

[root@demo1 conf]# grep --color "root" /etc/passwd

root:x:0:0:root:/root:/bin/bash

operator:x:11:0:operator:/root:/sbin/nologin

标记出第几行

[root@demo1 conf]# grep --color -n "root" /etc/passwd

1:root:x:0:0:root:/root:/bin/bash

10:operator:x:11:0:operator:/root:/sbin/nologin

grep正则^    例子:以root开头

[root@demo1 conf]# grep --color -n "^root" /etc/passwd

1:root:x:0:0:root:/root:/bin/bash

grep正则$    例子:以bash结尾

[root@demo1 conf]# grep --color -n “bash$" /etc/passwd

1:root:x:0:0:root:/root:/bin/bash

过滤出ip地址的行

[root@demo1 conf]# cat test.txt

192.168.3.3

10.0.0.1

111.111.111.11

11111.111.222.333

111.111.111.11.

[root@demo1 conf]# egrep --color "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" test.txt

192.168.3.3

10.0.0.1

111.111.111.11

简写

[root@demo1 conf]# egrep --color "^[0-9]{1,3}\.([0-9]{1,3}\.){2}[0-9]{1,3}$" test.txt

192.168.3.3

10.0.0.1

111.111.111.11

-c统计数量

[root@SBCE1 ipcs]# grep --color -c "sip" /archive/log/tracesbc/tracesbc_sip/tracesbc_sip_1640015158

4348

标签:中级,shell,grep,REGISTER,sip,CSeq,conf,root
来源: https://blog.csdn.net/u010036229/article/details/122482409

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有