キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 
cancel
35253
閲覧回数
10
いいね!
0
コメント
Ryota Takao
Cisco Employee
Cisco Employee

コマンドにパイプ(|)を追加すると、その後に指定するキーワードによって
指定した文字列に一致した部分だけを出力させる、コマンドの出力を保存するといったことが出来ます。

パイプ(|)は以下のようなキーワードと一緒に使用します。
*IOS の version によっては表示されないキーワードや使えないキーワードがあるので注意してください。

Router#show version | ?
  append    Append redirected output to URL (URLs supporting append operation
            only)
  begin     Begin with the line that matches
  count     Count number of lines which match regexp
  exclude   Exclude lines that match
  format    Format the output using the specified spec file
  include   Include lines that match
  redirect  Redirect output to URL
  section   Filter a section of output
  tee       Copy output to URL


以下にそれぞれのパイプのキーワードの使用例を示します。

■include
show コマンドの出力を指定した文字列を含む行だけ出力するように抑制します。
フォーマットは以下の通りです。
include <文字列>


<使用例>
以下に使用例を示します。
include を使用して出力を抑制する前の出力は以下の通りです。

Router#show interfaces GigabitEthernet 0/0/0
GigabitEthernet0/0/0 is up, line protocol is up
  Hardware is ISR4451-X-4x1GE, address is 3c08.f6d2.d0a0 (bia 3c08.f6d2.d0a0)
  MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA, loopback not set
  Keepalive not supported
  Full Duplex, 100Mbps, link type is auto, media type is RJ45
  output flow-control is unsupported, input flow-control is unsupported
  ARP type: ARPA, ARP Timeout 04:00:00
  Last input 00:00:17, output 00:00:46, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/40 (size/max)
  30 second input rate 0 bits/sec, 0 packets/sec
  30 second output rate 0 bits/sec, 0 packets/sec
     5547 packets input, 1821816 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
     0 watchdog, 5547 multicast, 0 pause input
     5094 packets output, 2205745 bytes, 0 underruns
     0 output errors, 0 collisions, 1 interface resets
     0 unknown protocol drops
     0 babbles, 0 late collision, 0 deferred
     0 lost carrier, 0 no carrier, 0 pause output
     0 output buffer failures, 0 output buffers swapped out


以下では include を使用して 30 second を含む行のみ出力させます。

Router#show interfaces GigabitEthernet 0/0/0 | include 30 second
  30 second input rate 0 bits/sec, 0 packets/sec
  30 second output rate 0 bits/sec, 0 packets/sec


また、複数の文字列を指定することも可能です。
複数の文字列を指定する場合のフォーマットは以下のようになります。

include <文字列1>|<文字列2>|<文字列3>...

以下の例では「30 second」、「drops」、「throttles」の3つの文字列を指定しています。
指定した文字列の何れかを含む行が出力されます。

Router#show interfaces GigabitEthernet 0/0/0 | include 30 second|drops|throttles       
  Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0
  30 second input rate 0 bits/sec, 0 packets/sec
  30 second output rate 0 bits/sec, 0 packets/sec
     0 runts, 0 giants, 0 throttles
     0 unknown protocol drops

残念ながら、AND 条件で出力させるということは出来ません。
例えば、「error」と「drop」の両方を含む行のみ出力させるといったことは出来ません。

 

■exclude
show コマンドの出力を指定した文字列を含まない行だけ出力するように抑制します。
フォーマットは以下の通りです。
exclude <文字列>


include の方が使いやすいのであまり使用する機会はないですが、drop カウンターなどの出力と組み合わせると
便利な場合があります。


<使用例>
以下に使用例を示します。
以下は抑制前の出力です。
Router#show platform hardware qfp active infrastructure punt statistics type per-cause
Global Per Cause Statistics

  Number of punt causes =   93

  Per Punt Cause Statistics
                                                        Packets          Packets
  Counter ID  Punt Cause Name                           Received         Transmitted      
  --------------------------------------------------------------------------------------
  000         Reserved                                  0                0                
  001         MPLS ICMP Can't Fragment                  0                0                
  002         IPv4 Options                              0                0                
  003         Layer2 control and legacy                 11537            11537            
  004         PPP Control                               0                0                
  005         CLNS IS-IS Control                        0                0                
  006         HDLC keepalives                           0                0                
  007         ARP request or response                   90               90               
--- snip ---

この出力を exclude を使用しカウンタが 0 以外の行を出力します。
文字列は「_0_」のように指定します。
以下の通りカウンタが0以外の行のみ出力されていることが確認できます。

Router#show platform hardware qfp active infrastructure punt statistics type per-cause | exclude _0_       
Load for five secs: 0%/0%; one minute: 0%; five minutes: 0%
No time source, *17:31:54.453 UTC Thu Apr 24 2014
Global Per Cause Statistics

  Number of punt causes =   93

  Per Punt Cause Statistics
                                                        Packets          Packets
  Counter ID  Punt Cause Name                           Received         Transmitted      
  --------------------------------------------------------------------------------------
  003         Layer2 control and legacy                 11537            11537            
  007         ARP request or response                   90               90      
         


指定する文字列を「_0_」ではなく「0」にするとこの例ではカウンタが何も出力されません。
理由は、この例では Counter ID の部分に 0 が含まれるのでそこに反応し除外してしまうためです。

Router#show platform hardware qfp active infrastructure punt statistics type per-cause  | exclude 0         
Global Per Cause Statistics

  Number of punt causes =   93

  Per Punt Cause Statistics
                                                        Packets          Packets
  Counter ID  Punt Cause Name                           Received         Transmitted      
  --------------------------------------------------------------------------------------


  Number of inject causes = 34

  Per Inject Cause Statistics
                                                        Packets          Packets
  Counter ID  Inject Cause Name                         Received         Transmitted      
  --------------------------------------------------------------------------------------

Router#

 

■begin
show コマンドの出力等を指定した文字列がある行から出力させます。
フォーマットは以下の通りです。
begin <文字列>

<使用例>
以下に使用例を示します。

beginを使用する前の出力は以下の通りです。

Router#show interfaces GigabitEthernet 0/0/0
GigabitEthernet0/0/0 is up, line protocol is up
  Hardware is ISR4451-X-4x1GE, address is 3c08.f6d2.d0a0 (bia 3c08.f6d2.d0a0)
  MTU 1500 bytes, BW 100000 Kbit/sec, DLY 100 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation ARPA, loopback not set
  Keepalive not supported
  Full Duplex, 100Mbps, link type is auto, media type is RJ45
  output flow-control is unsupported, input flow-control is unsupported
  ARP type: ARPA, ARP Timeout 04:00:00
  Last input 00:00:09, output 00:00:04, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/40 (size/max)
  30 second input rate 0 bits/sec, 0 packets/sec
  30 second output rate 0 bits/sec, 0 packets/sec
     5616 packets input, 1844643 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
     0 watchdog, 5616 multicast, 0 pause input
     5158 packets output, 2233457 bytes, 0 underruns
     0 output errors, 0 collisions, 1 interface resets
     0 unknown protocol drops
     0 babbles, 0 late collision, 0 deferred
     0 lost carrier, 0 no carrier, 0 pause output
     0 output buffer failures, 0 output buffers swapped out

begin を使用して途中から出力させると以下のようになります。

Router#show interfaces GigabitEthernet 0/0/0 | begin 30 second
  30 second input rate 0 bits/sec, 0 packets/sec
  30 second output rate 0 bits/sec, 0 packets/sec
     5616 packets input, 1844643 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
     0 watchdog, 5616 multicast, 0 pause input
     5158 packets output, 2233457 bytes, 0 underruns
     0 output errors, 0 collisions, 1 interface resets
     0 unknown protocol drops
     0 babbles, 0 late collision, 0 deferred
     0 lost carrier, 0 no carrier, 0 pause output
     0 output buffer failures, 0 output buffers swapped out

■count
指定した文字列を含む行の数をカウントします。
フォーマットは以下の通りです。
count <文字列>

この例では show interfaces GigabitEthernet 0/0/0 の出力に「error」が含まれる行が何行あるか確認しています。

Router#show interfaces GigabitEthernet 0/0/0 | count error
Number of lines which match regexp = 2

■section
文字列を含むセクションの情報を出力します。
フォーマットは以下の通りです。
section <文字列>

使用例を以下に示します。
この例では show running-config の GigabitEthernet0/0/0 のセクションの情報のみを出力しています。

Router#show running-config | section GigabitEthernet0/0/0
interface GigabitEthernet0/0/0
 no ip address
 load-interval 30
 negotiation auto

■redirect
出力をリダイレクトし、ファイルとして保存します。
指定したファイルがなければファイルを作成します。
指定したファイルが既に存在する場合は上書き保存します。
append は追記ですが、こちらは上書き保存になります。
違いに注意してください。

フォーマットは以下の通りです。
redirect <filesystem>:<file_name>

<使用例>
以下に使用例を示します。
show interfaces GigabitEthernet 0/0/0 stats の出力が bootflash 配下に stats.txt というファイル名で保存されていることが確認できます。

Router#show interfaces GigabitEthernet 0/0/0 stats | redirect bootflash:stats.txt

Router#more bootflash:stats.txt
GigabitEthernet0/0/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor       5753    1889942       5283    2287555
             Route cache          0          0          0          0
       Distributed cache       5753    1889942       5282    2287149
                   Total      11506    3779884      10565    4574704

■append
出力をリダイレクトし、指定したファイルに出力を追記します。
指定したファイルがなければファイルを作成します。
redirect は上書き保存ですが、append は追記になります。
違いに注意してください。

フォーマットは以下の通りです。
append <filesystem>:<file_name>


<使用例>
以下に使用例を示します。
redirect の項目で作成した bootflash:stats.txt に show interfaces GigabitEthernet 0/0/0 stats の出力を追記しています。

Router#show interfaces GigabitEthernet 0/0/0 stats | append bootflash:stats.txt

Router#more bootflash:stats.txt
GigabitEthernet0/0/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor       5753    1889942       5283    2287555
             Route cache          0          0          0          0
       Distributed cache       5753    1889942       5282    2287149
                   Total      11506    3779884      10565    4574704
GigabitEthernet0/0/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor       5758    1891717       5287    2289287
             Route cache          0          0          0          0
       Distributed cache       5758    1891717       5286    2288881
                   Total      11516    3783434      10573    4578168

■tee
コマンドの出力を表示し、かつ、出力をファイルに保存します。
指定したファイルがなければファイルを作成します。
指定したファイルが既に存在する場合は上書き保存します。

フォーマットは以下の通りです。
tee <filesystem>:<file_name>

<使用例>
以下に使用例を示します。

show interfaces GigabitEthernet 0/0/0 stats の出力が bootflash:stats.txt に保存されていることが確認できます。

Router#show interfaces GigabitEthernet 0/0/0 stats | tee bootflash:stats.txt
%Warning: There is a file already existing with this name
Do you want to over write? [confirm]
GigabitEthernet0/0/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor       5777    1897906       5305    2297081
             Route cache          0          0          0          0
       Distributed cache       5777    1897906       5304    2296675
                   Total      11554    3795812      10609    4593756

Router#more bootflash:stats.txt
GigabitEthernet0/0/0
          Switching path    Pkts In   Chars In   Pkts Out  Chars Out
               Processor       5777    1897906       5305    2297081
             Route cache          0          0          0          0
       Distributed cache       5777    1897906       5304    2296675
                   Total      11554    3795812      10609    4593756


■format
指定された spec ファイルを使用して出力を整形します。
フォーマットは以下の通りです。
format <filesystem>:<spec_file>

また、このコマンドは特定のコマンドでのみ使用可能です。
show format でどのコマンドで使用可能か確認できます。

Router#show format
The following CLI are supported in built-in
show inventory
show ip interface brief

<使用例>
以下に使用例を示します。
この例では test.odm を使用して show ip interface brief の出力がフォーマットされています。

Router#show ip interface brief | format bootflash:test.odm
<?xml version="1.0" encoding="UTF-8"?>
  <ShowIpInterfaceBrief xmlns="ODM://bootflash:emptyfile.odm//show_ip_interface_brief">
    <SpecVersion>built-in</SpecVersion>
    <IPInterfaces>
      <entry>
        <Interface>GigabitEthernet0/0/0</Interface>
        <OK>YES</OK>
        <Method>NVRAM</Method>
        <Status>up</Status>
        <Protocol>up</Protocol>
      </entry>
--- snip ---

 

Getting Started

検索バーにキーワード、フレーズ、または質問を入力し、お探しのものを見つけましょう

シスコ コミュニティをいち早く使いこなしていただけるよう役立つリンクをまとめました。みなさんのジャーニーがより良いものとなるようお手伝いします