有一堆從 snmpwalk 撈出來的資料, 部份資料如下:
IF-MIB::ifName.1000 = STRING: TenGigE0/0/0/22.43704
IF-MIB::ifName.1001 = STRING: TenGigE0/0/0/22.23723
IF-MIB::ifName.1002 = STRING: TenGigE0/0/0/22.33723
IF-MIB::ifName.1003 = STRING: TenGigE0/0/0/22.43723
IF-MIB::ifName.974 = STRING: GigabitEthernet0/2/1/7.2731
IF-MIB::ifName.976 = STRING: GigabitEthernet0/6/1/0.2556
IF-MIB::ifName.977 = STRING: GigabitEthernet0/6/1/0.2557
IF-MIB::ifName.978 = STRING: GigabitEthernet0/6/1/16.2696
IF-MIB::ifName.979 = STRING: GigabitEthernet0/6/1/16.2697
IF-MIB::ifName.980 = STRING: GigabitEthernet0/6/1/14.2686
IF-MIB::ifName.981 = STRING: GigabitEthernet0/6/1/14.2687
IF-MIB::ifName.982 = STRING: GigabitEthernet0/2/0/4.2672
IF-MIB::ifName.983 = STRING: GigabitEthernet0/2/0/4.2673
IF-MIB::ifName.984 = STRING: GigabitEthernet0/3/0/6.2716
IF-MIB::ifName.985 = STRING: GigabitEthernet0/3/0/6.2717
IF-MIB::ifName.986 = STRING: GigabitEthernet0/6/1/17.2680
IF-MIB::ifName.987 = STRING: GigabitEthernet0/6/1/17.2681
IF-MIB::ifName.988 = STRING: GigabitEthernet0/6/1/17.2678
IF-MIB::ifName.989 = STRING: GigabitEthernet0/6/1/17.2679
IF-MIB::ifName.990 = STRING: GigabitEthernet0/2/0/18.2652
問題來了, 如果我只想保留如:
IF-MIB::ifName.1003 = STRING: TenGigE0/0/0/22
IF-MIB::ifName.987 = STRING: GigabitEthernet0/6/1/17
IF-MIB::ifName.990 = STRING: GigabitEthernet0/2/0/18
也就是說, 不想要
IF-MIB::ifName.*= STRING: *.43723
這類 sub interface 的資料.
請問 regular expression 要如何下?? 小弟的 [^.] 是那裡弄錯了??
egrep '^.*ifName.*STRING.*[^.]' file.txt
看不太懂你不想要的是什麼...
如果只要刪除後面的小數點,其實你抓小數點位置,去裁切還比較快。
或者你用這個試試,^.+\/\d
,這是切出來的值是 IF-MIB::ifName.985 = STRING: GigabitEthernet0/3/0/6
awk -F. '{$NF=""}1' test.txt
這樣應該就可以了,之後再看你要另存到別的文件,還是要做其它處理