A bug in the IOS “section” filter

The section filter of the show commands contains a nasty bug (at least in the IOS release 12.4T) in IOS release 12.2SRC: if a line in the section matches the same regular expression as the section header, the rest of the section is not printed.I guess this sounds a bit perplexing, so here's an example. When using the router bgp regular expression in a section filter appended to the show running command, the whole BGP configuration is displayed:

PE-A#show run ¦ section router bgp
router bgp 65000
template peer-policy Internal
send-community both
exit-peer-policy
!
template peer-session Internal
remote-as 65000
update-source Loopback0
exit-peer-session
!
no synchronization
bgp log-neighbor-changes
neighbor 10.0.1.5 inherit peer-session Internal
neighbor 10.0.1.5 description PE-C(RR)
neighbor 10.0.1.5 inherit peer-policy Internal
no auto-summary
!
address-family vpnv4
neighbor 10.0.1.5 activate
neighbor 10.0.1.5 send-community extended
exit-address-family
However, if you use bgp as the regular expression, the printout starts with the router bgp command, but stops abruptly after the first line containing the string bgp, skipping the rest of the section:
PE-A#show run ¦ section bgp
router bgp 65000
template peer-policy Internal
send-community both
exit-peer-policy
!
template peer-session Internal
remote-as 65000
update-source Loopback0
exit-peer-session
!
no synchronization
bgp log-neighbor-changes

10 comments:

  1. How about using ^ in regexp to avoid this condition?
    show running-config | section ^router bgp

    ReplyDelete
  2. Sure you can, even the 'router bgp' without the caret would work; I wanted to point out the behavior when the section header as well as a line in the section match the same regular expression.

    ReplyDelete
  3. 1. This bug is specific to your platform/version - in my lab it isn't reproductible:

    lab01#sh run | section bgp
    router bgp 65519
    no synchronization
    bgp router-id 172.16.0.1
    bgp log-neighbor-changes
    redistribute connected
    redistribute static
    no auto-summary
    snmp-server enable traps bgp

    ReplyDelete
  4. 2. Maybe for this purpose this command has extended syntax:

    lab01#show running-config | section ?
    LINE Regular Expression
    exclude Exclude entire section(s) of output
    include Include entire section(s) of output

    lab01#show running-config | section

    ReplyDelete
  5. I'm also unable to produce this, running 12.4(6)T11 on an 1801.

    ReplyDelete
  6. My fault ... it was 12.2SRC. Fixed the post. Thanks for all the comments, you guys are great!

    ReplyDelete
  7. Question to the owner of 1801 running 12.4(6)T11 :
    which version of adsl microcode you use?

    ReplyDelete
  8. Ivan, I see the same issue here, so I created CSCsq16838 for you. Cheers.

    ReplyDelete
  9. @Xavier: You're fantastic. Thanks.

    Looks like there is still an easy way to submit bug reports to Cisco :) Something I've been hoping to find for the last 10 years :))

    ReplyDelete
  10. fix ready, waiting for commit

    ReplyDelete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.