parse the dump files

Being a Unix dummy, I was assigned a tough task to parse out data from router dump files. I hope somebody can give some idea how to achieve it.

one of dump file has following format

====start show inventory====

show inventory
NAME: "Chassis", DESCR: "12008/GRP chassis, Hw Serial#: 63900819, Hw Revision: 0x05"
PID: 73-2587-1 rev 80 dev 0, VID: 0x05, SN: 63900819   

NAME: "slot 0", DESCR: "RP"
PID: 800-2427-03 rev A0 dev 0, VID: V00, SN: CAB0544L3Q4

NAME: "slot 1", DESCR: "12 port Copper DS3"
PID: 800-5023-02 rev A0 dev 0, VID: V00, SN: SDK04230R3C
 

GW7.EWR1>
====end show inventory====
====start diag summary====
show diag summary
SLOT 0  (RP/LC 0 ): Route Processor
SLOT 1  (RP/LC 1 ): 12 Port Packet over DS3
SLOT 2  (RP/LC 2 ): 4 Port ISE ATM Over SONET OC-12/STM-4 Multi Mode
GW7.EWR1>
====end diag summary====
====start interfaces desc====
show interfaces desc
Interface              Status         Protocol Description
Se1/0                  admin down     down     
Se1/1                  up                 up      wcomw0s66573::T3
Se1/2                  admin down     down  spare
Se1/2.500              admin down   down  spare
Se1/3                  up                 up       u193283
Se1/4                  admin down     down     spare
Se1/5                  up                 up       wcomw0k67554 T3 RR8, PNL 11, JK: 1 w0e66539 1/14/04
Se1/6                  down              down     u218916:thomson.com:T3
Se1/7                  admin down     down     spare
Se1/8                  admin down     down     spare
Se1/9                  admin down     down     spare
Se1/9.500              admin down    down     pend               
     
GW7.EWR1>
====end interfaces desc====
====start show running-config====
show running-config
               ^
% Invalid input detected at '^' marker.

GW7.EWR1>

====end show running-config====

What I need to do is to parse out data between

"====start interfaces desc====" 

and

"GW7.EWR1>
====end interfaces desc===="

in another word, parse out floowing part and append to another file xyz.csv

Interface              Status         Protocol Description
Se1/0                  admin down     down     
Se1/1                  up                 up      wcomw0s66573::T3
Se1/2                  admin down     down  spare
Se1/2.500              admin down   down  spare
Se1/3                  up                 up       u193283
Se1/4                  admin down     down     spare
Se1/5                  up                 up       wcomw0k67554 T3 RR8, PNL 11, JK: 1 w0e66539 1/14/04
Se1/6                  down              down     u218916:thomson.com:T3
Se1/7                  admin down     down     spare
Se1/8                  admin down     down     spare
Se1/9                  admin down     down     spare
Se1/9.500              admin down    down     pend 

Thanks in advance

hi, It is not clear which data you want to parse out, please use code tags and simply provide an output data.

---------- Post updated at 08:04 PM ---------- Previous update was at 07:37 PM ----------

this one might not work all the time but to give an idea:

/usr/sfw/bin/ggrep "start interfaces desc" -A 14 -B 0  FILE

and If you need to grep only interface status with a suitable regex you can parse them:

awk '/[Ss]e[0-9]\/[0-9]/' FILE

---------- Post updated at 09:37 PM ---------- Previous update was at 08:04 PM ----------

this one might be a bit generic and better:

awk '/Interface Status/ || /[A-Za-z]+[0-9]\/[0-9]/'  FILE

Result:

Interface Status Protocol Description
Se1/0 admin down down 
Se1/1 up up wcomw0s66573::T3
Se1/2 admin down down spare
Se1/2.500 admin down down spare
Se1/3 up up u193283
Se1/4 admin down down spare
Se1/5 up up wcomw0k67554 T3 RR8, PNL 11, JK: 1 w0e66539 1/14/04
Se1/6 down down u218916:thomson.com:T3
Se1/7 admin down down spare
Se1/8 admin down down spare
Se1/9 admin down down spare
Se1/9.500 admin down down pend
awk '/start interfaces desc/,/end interfaces desc/' urfile |egrep "^Interface|^Se" > xyz.csv

Or just awk...

awk '/start interfaces desc/,/end interfaces desc/{if($0 ~ /^[Interface|Se]/) print}' infile

Provide whole input please and use code tags so that we can easily see what u need

If some data is common in each files then a code can parse the desired part just like my trying to parse serial interface status In first code. But without seing your input files i cant say something certain, can you give a few input files?

Ok, try this.

1) Pick up one dump file that is not too big. Paste the contents over here between [ code ] and [ /code ] tags. Note that those are square brackets ("[" and "]") and not inequality signs ("<" and ">"). And there's no space around the square brackets.

2) Color the head, data and bottom parts of your dump file in 3 different colors (instead of adding any text of your own).

3) Outside of the "code" tags, mention what color represents what (e.g. red means head part, blue means data part, yellow means end part etc.) and tell us what colored portion you want to extract from the dump file.

Here's a demo -

Line number 1
Line number 2
 Line number 3
Line number 4
 Line number 5
Line number 6
Line number 7

Red = head part
Blue = data part
Green = end part
Black = part that I don't care about

I want to extract the part in blue color.

HTH,
tyler_durden

Like Durden said try to make clear what you need, however try this, im not sure if this code responses your requirement:

awk '/Interfaces desc/ || /[A-Za-z]+[0-9]\/[0-9] || [A-Za-z]+[0-9]\/[0-9]+\.*/' FILE > output.csv

What do you get with this code? I can't test it now sorry thats why im asking:

awk '/[Ii]nterfaces desc/ || /[A-Z][A-Za-z][0-9].*/ || /[A-Z][A-Za-z][0-9]\/[0-9]+.*/' FILE > myfile.csv
awk '/start interfaces desc/,/end interfaces desc/ {$1 ~ /[A-Z][A-Za-z][0-9]+/ || 
/[A-Z][A-Za-z][0-9]\/[A-Za-z0-9].*/}' FILE > myfile.csv

As always.... If on Solaris, try either 'nawk' or '/usr/xpg4/bin/awk' (instead of broken ol' awk).

nawk '/start interfaces desc/,/end interfaces desc/  {
  if ( ($1 ~ /[A-Z][A-Za-z][0-9]+/) || ($0 ~ "[A-Z][A-Za-z][0-9][/][A-Za-z0-9].*
") )
    print
}'  137.39.7.181_Cisco_12008.txt

Hello, slatefast:

A SED script, tested on all three files you attached earlier in the thread (one of which seems to have a line of dashes just before the data to be pulled begins):

#n
/^====start interfaces desc====/ {
    :top
    n; /^Interface/! b top
    n; /^--*.$/n

    :pr_data
    /^====end interfaces desc====/! {
        p; n; b pr_data
    }
}

In the code above, note that it is important that the first line begin with "#n".

Sample run:

$ sed -f slatefast.sed 137.39.7.205_Cisco_CRS-8_S.txt       
Lo0                up          up          External Loopback
Lo1                up          up          Internal Loopback
Nu0                up          up          
Te0/0/0/0          up          up          u271289:akamai.com:10GigE
Te0/0/1/0          up          up          u271154:akamai.com:10GigE
Te0/0/2/0          up          up          u271156:akamai.com:10GigE
Te0/0/4/0          up          up          u271158:akamai.com:10GigE
Gi0/1/0/0          admin-down  admin-down  
Gi0/1/0/1          up          up          u271793:Booz Allen Hamilton 
Gi0/1/0/2          up          up          u275786:revelationnetworks.com:GigE
Gi0/1/0/3          admin-down  admin-down  
Gi0/1/0/4          admin-down  admin-down  
Gi0/1/0/5          admin-down  admin-down  
Gi0/1/0/6          admin-down  admin-down  
Gi0/1/0/7          admin-down  admin-down  
Gi0/1/1/0          admin-down  admin-down  
Gi0/1/1/1          admin-down  admin-down  
Gi0/1/1/2          admin-down  admin-down  
Gi0/1/1/3          up          up          u274048
Gi0/1/1/4          admin-down  admin-down  
Gi0/1/1/5          admin-down  admin-down  
Gi0/1/1/6          admin-down  admin-down  
Gi0/1/1/7          admin-down  admin-down  
Gi0/1/2/0          up          up          
Gi0/1/2/1          admin-down  admin-down  
Gi0/1/2/2          admin-down  admin-down  
Gi0/1/2/3          admin-down  admin-down  
Gi0/1/2/4          admin-down  admin-down  
Gi0/1/2/5          admin-down  admin-down  
Gi0/1/2/6          admin-down  admin-down  
Gi0/1/2/7          admin-down  admin-down  
Gi0/1/4/0          admin-down  admin-down  
Gi0/1/4/1          admin-down  admin-down  
Gi0/1/4/2          admin-down  admin-down  
Gi0/1/4/3          admin-down  admin-down  
Gi0/1/4/4          admin-down  admin-down  
Gi0/1/4/5          admin-down  admin-down  
Gi0/1/4/6          admin-down  admin-down  
Gi0/1/4/7          admin-down  admin-down  
Te0/2/0/0          up          up          u269136:TTeliaSonera:10GigE
Te0/2/1/0          up          up          mwx00539:TTeliaSonera:10GigE
Te0/2/2/0          up          up          u278188:LimeLight:10GigE
Te0/2/4/0          up          up          u278189:LimeLight:10GigE
Te0/3/0/0          up          up          u278196::LimeLight Networks
Te0/3/1/0          up          up          u278197::LimeLight Networks
Te0/3/2/0          up          up          u278198::LimeLight Networks
Te0/3/4/0          up          up          u116910::Internap
Te0/4/0/0          up          up          To ge-0/1/0.XL3.IAD8
Te0/4/1/0          admin-down  admin-down  
Te0/4/2/0          admin-down  admin-down  
Te0/4/4/0          admin-down  admin-down  
Te0/5/0/0          up          up          To ge-0/1/0.XL4.IAD8
Te0/5/1/0          admin-down  admin-down  
Te0/5/2/0          admin-down  admin-down  
Te0/6/0/0          up          up          To ge-5/3/0.XL3.IAD8
Te0/6/1/0          up          up          To ge-3/0/0.XL3.IAD8
Te0/6/2/0          up          up          To ge-3/1/0.XL3.IAD8
Te0/6/4/0          up          up          To ge-3/2/0.XL3.IAD8
Te0/7/0/0          up          up          To ge-5/3/0.XL4.IAD8
Te0/7/1/0          up          up          To ge-3/0/0.XL4.IAD8
Te0/7/2/0          up          up          To ge-3/1/0.XL4.IAD8
Te0/7/4/0          up          up          To ge-3/2/0.XL4.IAD8
Mg0/RP0/CPU0/0     admin-down  admin-down  
Mg0/RP1/CPU0/0     admin-down  admin-down  MANAGEMENT_NETWORK_RP0

RP/0/RP0/CPU0:GW1.IAD8#

Regards,
Alister

Try this:

nawk '/start interfaces desc/,/end interfaces desc/  {if ( ($1 ~ /[A-Z][A-Za-z][0-9]+/) || ($0 ~ "[A-Z][A-Za-z][0-9][/][A-Za-z0-9].*") )    print "'$ip'" , $0}'  $file  >> output.csv