grep一次性排除多个选项
程序员文章站
2022-03-11 11:51:10
...
本文使用的文件内容如下
<office-wan>dis
<office-wan>display cu
<office-wan>display current-configuration
!Software Version V200R003C00SPC300
#
sysname office-wan
#
FTP server enable
#
lldp enable
#
interface Vlanif1
#
interface MEth0/0/1
ip address 192.168.1.5 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type access
#
interface GigabitEthernet0/0/2
port link-type access
#
interface GigabitEthernet0/0/3
description SMB_SERVER
port link-type access
stp bpdu-filter enable
stp edged-port enable
#
interface GigabitEthernet0/0/4
description M_IKUAI_ETH2
port link-type access
#
interface GigabitEthernet0/0/5
port link-type access
#
interface GigabitEthernet0/0/6
description S_IKUAI_ETH2
port link-type access
port default vlan 27
#
interface GigabitEthernet0/0/7
description LIANTONG_AD
port link-type access
port default vlan 27
#
interface GigabitEthernet0/0/8
port link-type access
#
interface GigabitEthernet0/0/9
port link-type access
#
interface GigabitEthernet0/0/10
port link-type access
#
interface GigabitEthernet0/0/11
port link-type access
#
interface GigabitEthernet0/0/12
port link-type access
#
interface GigabitEthernet0/0/13
#
interface GigabitEthernet0/0/14
port link-type access
#
interface GigabitEthernet0/0/15
port link-type access
#
interface GigabitEthernet0/0/16
port link-type access
#
interface GigabitEthernet0/0/17
port link-type access
#
interface GigabitEthernet0/0/18
port link-type access
#
interface GigabitEthernet0/0/19
port link-type access
#
interface GigabitEthernet0/0/20
port link-type access
#
interface GigabitEthernet0/0/21
combo-port fiber
port link-type access
#
interface GigabitEthernet0/0/22
port link-type access
#
interface GigabitEthernet0/0/23
port link-type access
#
interface GigabitEthernet0/0/24
port link-type access
#
interface NULL0
#
ip route-static 0.0.0.0 0.0.0.0 192.168.1.1
#
snmp-agent
snmp-agent local-engineid 800007DB03688F84F3C0A0
snmp-agent community read cipher %$%$x)"_4C}lm;ZwPD$eRPHAfS<E{L0w)Yk%M<[email protected]<Hf%(@r,C9JAInsu7*>SGq"<QfS%$%$
snmp-agent sys-info version all
#
stelnet server enable
ssh authentication-type default password
#
nqa test-instance ptadmin shiwei
#
user-interface con 0
authentication-mode password
set authentication password cipher %@%@\Ne7HGs'5Mky^]Mx%)T9.t<bI!{g1tP*!~BolhK$SUE.t<e.%@%@
user-interface vty 0 4
acl 2000 inbound
authentication-mode aaa
protocol inbound all
user-interface vty 16 20
#
return
现在需要将里面的所有交换机的接口名称取出来关键词interface
[[email protected] ~]# cat 1111.log | grep "interface"
interface Vlanif1
interface MEth0/0/1
interface GigabitEthernet0/0/1
interface GigabitEthernet0/0/2
interface GigabitEthernet0/0/3
interface GigabitEthernet0/0/4
interface GigabitEthernet0/0/5
interface GigabitEthernet0/0/6
interface GigabitEthernet0/0/7
interface GigabitEthernet0/0/8
interface GigabitEthernet0/0/9
interface GigabitEthernet0/0/10
interface GigabitEthernet0/0/11
interface GigabitEthernet0/0/12
interface GigabitEthernet0/0/13
interface GigabitEthernet0/0/14
interface GigabitEthernet0/0/15
interface GigabitEthernet0/0/16
interface GigabitEthernet0/0/17
interface GigabitEthernet0/0/18
interface GigabitEthernet0/0/19
interface GigabitEthernet0/0/20
interface GigabitEthernet0/0/21
interface GigabitEthernet0/0/22
interface GigabitEthernet0/0/23
interface GigabitEthernet0/0/24
interface NULL0
user-interface con 0
user-interface vty 0 4
user-interface vty 16 20
可是里面包含了很多我们不想要的信息,例如user开头的
[[email protected] ~]# cat 1111.log | grep "interface" | grep "^i" #取以i开头的信息
interface Vlanif1
interface MEth0/0/1
interface GigabitEthernet0/0/1
interface GigabitEthernet0/0/2
interface GigabitEthernet0/0/3
interface GigabitEthernet0/0/4
interface GigabitEthernet0/0/5
interface GigabitEthernet0/0/6
interface GigabitEthernet0/0/7
interface GigabitEthernet0/0/8
interface GigabitEthernet0/0/9
interface GigabitEthernet0/0/10
interface GigabitEthernet0/0/11
interface GigabitEthernet0/0/12
interface GigabitEthernet0/0/13
interface GigabitEthernet0/0/14
interface GigabitEthernet0/0/15
interface GigabitEthernet0/0/16
interface GigabitEthernet0/0/17
interface GigabitEthernet0/0/18
interface GigabitEthernet0/0/19
interface GigabitEthernet0/0/20
interface GigabitEthernet0/0/21
interface GigabitEthernet0/0/22
interface GigabitEthernet0/0/23
interface GigabitEthernet0/0/24
interface NULL0
可是里面还是有类似于Vlanif1这些信息不是我们想要的
[[email protected] ~]# cat 1111.log | grep "interface" | grep "^i" | grep -vE "(Vlanif1| MEth0/0/1|NULL0)"
interface GigabitEthernet0/0/1
interface GigabitEthernet0/0/2
interface GigabitEthernet0/0/3
interface GigabitEthernet0/0/4
interface GigabitEthernet0/0/5
interface GigabitEthernet0/0/6
interface GigabitEthernet0/0/7
interface GigabitEthernet0/0/8
interface GigabitEthernet0/0/9
interface GigabitEthernet0/0/10
interface GigabitEthernet0/0/11
interface GigabitEthernet0/0/12
interface GigabitEthernet0/0/13
interface GigabitEthernet0/0/14
interface GigabitEthernet0/0/15
interface GigabitEthernet0/0/16
interface GigabitEthernet0/0/17
interface GigabitEthernet0/0/18
interface GigabitEthernet0/0/19
interface GigabitEthernet0/0/20
interface GigabitEthernet0/0/21
interface GigabitEthernet0/0/22
interface GigabitEthernet0/0/23
interface GigabitEthernet0/0/24
最后我们将接口名称取出来
[[email protected] ~]# cat 1111.log | grep "interface" | grep "^i" | grep -vE "(Vlanif1| MEth0/0/1|NULL0)" | awk '{print $2}'
GigabitEthernet0/0/1
GigabitEthernet0/0/2
GigabitEthernet0/0/3
GigabitEthernet0/0/4
GigabitEthernet0/0/5
GigabitEthernet0/0/6
GigabitEthernet0/0/7
GigabitEthernet0/0/8
GigabitEthernet0/0/9
GigabitEthernet0/0/10
GigabitEthernet0/0/11
GigabitEthernet0/0/12
GigabitEthernet0/0/13
GigabitEthernet0/0/14
GigabitEthernet0/0/15
GigabitEthernet0/0/16
GigabitEthernet0/0/17
GigabitEthernet0/0/18
GigabitEthernet0/0/19
GigabitEthernet0/0/20
GigabitEthernet0/0/21
GigabitEthernet0/0/22
GigabitEthernet0/0/23
GigabitEthernet0/0/24
补充grep and操作
cat 22222.log | grep -E "GigabitEthernet.*up" | grep -vE "up.*down" | awk '{print $1"\t"$2"\t"$3}'
GigabitEthernet0/0/1 up up
GigabitEthernet0/0/2 up up
GigabitEthernet0/0/13 up up
GigabitEthernet0/0/14 up up
GigabitEthernet0/0/15 up up
GigabitEthernet0/0/16 up up
GigabitEthernet0/0/24 up up
其中GigabitEthernet.*up是grep的and操作
上一篇: 数组与矩阵---最长可整合子数组的长度
下一篇: git-bash主题设置
推荐阅读