Useful Regex Filters for Huawei Switches

A regex filter appended to display interface cuts the output on Huawei switches down to exactly the lines you need: interface name and discard counters.
On a switch with 48 or more ports, display interface quickly produces several hundreds of lines. When you are looking for packet loss, for example output discards on ports, you do not want to scroll through every counter. Huawei VRP and YunShan provides pipe filters with regular expressions that do exactly this.

Basics: pipe filters

Any display command accepts a filter appended with |. The expression behind it is a regular expression, not a plain string.

Filter

Effect

| include <regex> shows only matching lines
| exclude <regex> hides matching lines
| begin <regex> shows everything from the first matching line onward
| count counts the lines of the output (depending on version)

Three regex elements matter for this use case:

  • | inside the expression is an OR, e.g. current state|Discard
  • ^ anchors to the start of a line, e.g. ^Output
  • [1-9] and * allow targeted number patterns, e.g. Discard: *[1-9]

So the first | is the pipe operator, every further | belongs to the regex.

Know your output

The examples in this article are based on a Huawei S5735-L8P4X-QA-V2 switch that names its ports GE1/0/x and 10GE1/0/x. Three details of its display interface output decide which filters work:

<HUAWEI> dis int GE1/0/2
GE1/0/2 current state : UP (ifindex: 4)
Line protocol current state : UP
Description: Workstation
Switch Port, PVID :   30, TPID : 8100(Hex), The Maximum Frame Length is 9216
Internet protocol processing : disabled
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 108f-fe95-7900
Port Mode:    COMMON COPPER,     Port Split:                         -
Speed:                 1000,     Loopback:                        NONE
Duplex:                FULL,     Negotiation:                   ENABLE
Input Flow-control: DISABLE,     Output Flow-control:          DISABLE
Mdi:                   AUTO
Last physical up time   : 2025-09-21 05:18:04
Last physical down time : 2025-09-21 05:18:01
Current system time: 2025-09-21 18:14:03
Statistics last cleared:never
    Last 300 seconds input rate: 41484 bits/sec, 14 packets/sec
    Last 300 seconds output rate: 150783 bits/sec, 24 packets/sec
    Input peak rate 81539587 bits/sec, Record time: 2025-09-20 14:02:51
    Output peak rate 123562995 bits/sec, Record time: 2025-09-20 16:50:34
    Input :        10918242957 bytes,           28831661 packets
    Output:       171881338103 bytes,          126472041 packets
    Input:
      Unicast:               28757093,   Multicast:                   49577
      Broadcast:                24972,   Jumbo:                           0
      Discard:                      0,   Frames:                         --
      Pause:                        0,   Ignoreds:                        0

      Total Error:                  0
      CRC:                          0,   Giants:                          0
      Jabbers:                     --,   Fragments:                       0
      Runts:                        0,   DropEvents:                      0
      Alignments:                   0,   Symbols:                         0

    Output:
      Unicast:              122997238,   Multicast:                 2041481
      Broadcast:              1433322,   Jumbo:                           0
      Discard:                   2842,   Buffers Purged:                  0
      Pause:                        0

      Total Error:                  0

    FEC:
      FEC Corrected Errors:                      0
      FEC Uncorrected Errors:                    0

    Input bandwidth utilization threshold : 90.00%
    Output bandwidth utilization threshold: 90.00%
    Last 300 seconds input utility rate:  0.01%
    Last 300 seconds output utility rate: 0.01%

  • current state appears twice per interface, also in Line protocol current state. Filter on GE[0-9/]+ current instead; it matches GE, 10GE, 25GE, 40GE and 100GE ports and nothing else.
  • Input: and Output: are indented and Output: appears twice (byte totals and block header). A filter like ^Output finds nothing.
  • The two Discard lines can be told apart by their neighbor: the input discard is followed by Frames, the output discard by Buffers Purged. That makes block headers unnecessary.

Showing interface name and discards

Input and output discards per interface:

display interface | include GE[0-9/]+ current|Discard

<HUAWEI>display interface | include GE[0-9/]+ current|Discard
10GE1/0/1 current state : DOWN (ifindex: 11)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
10GE1/0/2 current state : DOWN (ifindex: 12)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
10GE1/0/3 current state : UP (ifindex: 13)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
10GE1/0/4 current state : UP (ifindex: 14)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
GE1/0/1 current state : UP (ifindex: 3)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
GE1/0/2 current state : UP (ifindex: 4)
      Discard:                      0,   Frames:                         --
      Discard:                   2842,   Buffers Purged:                  0
GE1/0/3 current state : UP (ifindex: 5)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
GE1/0/4 current state : UP (ifindex: 6)
      Discard:                      0,   Frames:                         --
      Discard:                 280976,   Buffers Purged:                  0
GE1/0/5 current state : DOWN (ifindex: 7)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
GE1/0/6 current state : UP (ifindex: 8)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
GE1/0/7 current state : UP (ifindex: 9)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0
GE1/0/8 current state : UP (ifindex: 10)
      Discard:                      0,   Frames:                         --
      Discard:                      0,   Buffers Purged:                  0

The first discard line is input, the second is output. To see output discards only, filter on the neighbor field:

display interface | include GE[0-9/]+ current|Buffers Purged

<HUAWEI>display interface | include GE[0-9/]+ current|Buffers Purged
10GE1/0/1 current state : DOWN (ifindex: 11)
      Discard:                      0,   Buffers Purged:                  0
10GE1/0/2 current state : DOWN (ifindex: 12)
      Discard:                      0,   Buffers Purged:                  0
10GE1/0/3 current state : UP (ifindex: 13)
      Discard:                      0,   Buffers Purged:                  0
10GE1/0/4 current state : UP (ifindex: 14)
      Discard:                      0,   Buffers Purged:                  0
GE1/0/1 current state : UP (ifindex: 3)
      Discard:                      0,   Buffers Purged:                  0
GE1/0/2 current state : UP (ifindex: 4)
      Discard:                   2842,   Buffers Purged:                  0
GE1/0/3 current state : UP (ifindex: 5)
      Discard:                      0,   Buffers Purged:                  0
GE1/0/4 current state : UP (ifindex: 6)
      Discard:                 280976,   Buffers Purged:                  0
GE1/0/5 current state : DOWN (ifindex: 7)
      Discard:                      0,   Buffers Purged:                  0
GE1/0/6 current state : UP (ifindex: 8)
      Discard:                      0,   Buffers Purged:                  0
GE1/0/7 current state : UP (ifindex: 9)
      Discard:                      0,   Buffers Purged:                  0
GE1/0/8 current state : UP (ifindex: 10)
      Discard:                      0,   Buffers Purged:                  0

For input discards only, replace Buffers Purged with Frames. 

Non-zero discards only

A number pattern hides every output discard line with a value of 0:

display interface | include GE[0-9/]+ current|Discard: *[1-9].*Buffers Purged

Discard: *[1-9] only matches when a digit from 1 to 9 follows the colon and any number of spaces. .*Buffers Purged limits the match to the output block. 

<HUAWEI>display interface | include GE[0-9/]+ current|Discard: *[1-9].*Buffers Purged
10GE1/0/1 current state : DOWN (ifindex: 11)
10GE1/0/2 current state : DOWN (ifindex: 12)
10GE1/0/3 current state : UP (ifindex: 13)
10GE1/0/4 current state : UP (ifindex: 14)
GE1/0/1 current state : UP (ifindex: 3)
GE1/0/2 current state : UP (ifindex: 4)
      Discard:                   2842,   Buffers Purged:                  0
GE1/0/3 current state : UP (ifindex: 5)
GE1/0/4 current state : UP (ifindex: 6)
      Discard:                 280976,   Buffers Purged:                  0
GE1/0/5 current state : DOWN (ifindex: 7)
GE1/0/6 current state : UP (ifindex: 8)
GE1/0/7 current state : UP (ifindex: 9)
GE1/0/8 current state : UP (ifindex: 10)

An interface with output discards shows its discard line directly below its name. For non-zero input discards use Discard: *[1-9].*Frames, for both directions Discard: *[1-9].

Limitations and tips

  • Line by line: include checks every line on its own and has no context. Hiding interfaces entirely just because they have no discards is not possible with YunShan/VRP's built-in tools.
  • Check the format first: Indentation, field order and port names vary between platforms and firmware versions. Before relying on a filter, look at the raw output of one interface with display interface 10GE1/0/1.
  • Case sensitivity: The filter is case-sensitive. discard does not find Discard, up does not find UP.
  • Clean measurement: Reset the counters first with reset counters interface 10GE1/0/1, then measure again.

Do you have any favorite regex filters? Let us know below in the comments!

Comments (0)

No comments yet. Be the first to share your thoughts.

Leave a Comment

Newsletter

Get information about new guides, courses, and training updates directly via email.

Main Menu Offcanvas (de)