Parsing information in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing information in perl
# 1  
Old 04-29-2011
Parsing information in perl

So i'm trying to write a perl script that logins into a network switch via ssh:

Code:
#sh ip traffic
IP statistics:
  Rcvd:  1460119147 total, 563943377 local destination
         0 format errors, 0 checksum errors, 48401998 bad hop count
         0 unknown protocol, 8379279 not a gateway
         0 security failures, 0 bad options, 3000229 with options
  Opts:  0 end, 0 nop, 0 basic security, 0 loose source route
         0 timestamp, 0 extended security, 0 record route
         0 stream ID, 0 strict source route, 3000229 alert, 0 cipso, 0 ump
         0 other
  Frags: 0 reassembled, 0 timeouts, 0 couldn't reassemble
         133 fragmented, 0 couldn't fragment
  Bcast: 162123 received, 638 sent
  Mcast: 559988802 received, 460949771 sent
  Sent:  464766639 generated, 47809047 forwarded
  Drop:  175 encapsulation failed, 0 unresolved, 0 no adjacency
         0 no route, 0 unicast RPF, 0 forced drop
         0 options denied, 0 source IP address zero

ICMP statistics:
  Rcvd: 0 format errors, 0 checksum errors, 0 redirects, 5 unreachable
        179894 echo, 10 echo reply, 0 mask requests, 0 mask replies, 0 quench
        0 parameter, 0 timestamp, 0 info request, 0 other
        0 irdp solicitations, 0 irdp advertisements
  Sent: 0 redirects, 0 unreachable, 10 echo, 179894 echo reply
        0 mask requests, 0 mask replies, 0 quench, 0 timestamp
        0 info reply, 0 time exceeded, 0 parameter problem
        0 irdp solicitations, 0 irdp advertisements

BGP statistics:
  Rcvd: 0 total, 0 opens, 0 notifications, 0 updates
        0 keepalives, 0 route-refresh, 0 unrecognized
  Sent: 0 total, 0 opens, 0 notifications, 0 updates
        0 keepalives, 0 route-refresh

TCP statistics:
  Rcvd: 108508 total, 0 checksum errors, 54 no port
  Sent: 178403 total

PIMv2 statistics: Sent/Received
  Total: 324833847/421784683, 0 checksum errors, 0 format errors
  Registers: 0/0 (0 non-rp, 0 non-sm-group), Register Stops: 0/0,  Hellos: 77244                                                                                                                                                             1/771785
  Join/Prunes: 49817/13595, Asserts: 37217/62716, grafts: 34117/549
  Bootstraps: 0/0, Candidate_RP_Advertisements: 0/0
  State-Refresh: 323940174/420901921

IGMP statistics: Sent/Received
  Total: 175274/3417276, Format errors: 0/0, Checksum errors: 0/0
  Host Queries: 70204/311578, Host Reports: 105070/3103909, Host Leaves: 0/1555
  DVMRP: 0/0, PIM: 0/0

UDP statistics:
  Rcvd: 129384120 total, 0 checksum errors, 5700 no port
  Sent: 130327644 total, 154691 forwarded broadcasts

OSPF statistics:
  Rcvd: 0 total, 0 checksum errors
        0 hello, 0 database desc, 0 link state req
        0 link state updates, 0 link state acks

  Sent: 0 total
        0 hello, 0 database desc, 0 link state req
        0 link state updates, 0 link state acks

IP-EIGRP statistics:
  Rcvd: 9069505 total
  Sent: 9072113 total

Probe statistics:
  Rcvd: 0 address requests, 0 address replies
        0 proxy name requests, 0 where-is requests, 0 other
  Sent: 0 address requests, 0 address replies (0 proxy)
        0 proxy name replies, 0 where-is replies

ARP statistics:
  Rcvd: 61692393 requests, 47509 replies, 0 reverse, 0 other
  Sent: 3790957 requests, 199197 replies (3168 proxy), 0 reverse
  Drop due to input queue full: 0

I basically want to parse the number in bold after where it says "Bad Hop Count"

I would like to get the output like so:

Code:
48401998

I'm assuming using awk within perl? Any help is appreciated.
# 2  
Old 04-29-2011
This should get you started ...

#sh ip traffic | grep ' bad hop count' | cut -d, -f3
# 3  
Old 04-30-2011
Code:
#sh ip traffic | perl -lne 'print $1 if /(\d+) bad hop count/'

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in parsing an input in perl

I am executing a command it is returning me something like this name ip port ------------------------------------ http-listener-1 * 6712 http-listener-2 * 8709 I have a subroutine getListenerName($porttobeChecked) This subroutine returns me the name of the listener if i pass a... (4 Replies)
Discussion started by: javaholics
4 Replies

2. Programming

Adding information to c file using perl

Hi, I have c file which contains more number of tests. two or more tests in one c file. I have the XMl data regarding tests. i need to add this xml data to c file at before the test. I know which file having which test and i created hash table for that. so the problem is i have to add information... (13 Replies)
Discussion started by: veerubiji
13 Replies

3. Shell Programming and Scripting

parsing argument in perl

in bash: LIST=`cat $1` for i in $LIST do ... done how will i do this in perl ? $1 is my first arguement. I'm a newbie in perl and will appreciate much your help guys ... (4 Replies)
Discussion started by: linuxgeek
4 Replies

4. Shell Programming and Scripting

Perl log parsing help

Hello, I'm sure this is a very simple problem, but I'm having trouble thinking of an efficient way to do the following: given a large centralized ssh-log, one file on a syslog server, not separated by machines (I wish it were), that looks something like this: Sep 27 16:20:56 machine-name... (1 Reply)
Discussion started by: droog72
1 Replies

5. Shell Programming and Scripting

Perl script parsing Help

Hi All, I am looking for a parsing in perl script which will parse DJEČJI SVIJET. There is a unicode character above character C. How to parse the total DJEČJI SVIJET in perl. Regards, Harikrishna (3 Replies)
Discussion started by: Harikrishna
3 Replies

6. Shell Programming and Scripting

cant get perl to pull information right

Hello, I cant get the perl script to pull the information from Sark DNS 4.X Options ACL Templates= and other= Can someone look at the script to see why and fix it please. FYI..Under Sark DNS 4.x ACL Templates= and other= has an indent/tab, not sure if thats the reason my the script... (24 Replies)
Discussion started by: richsark
24 Replies

7. Programming

Parsing a string in PERL

I have an extractfile (with fields delimited by pipes '|') and I want to prepend a counter based on the below requirements: - The counter starts at 3. - The counter increments only if the date (67th field of the extractfile) is different. Below is what I started off with: $cnt=2;... (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

8. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

9. Shell Programming and Scripting

Perl: parsing variables

I have the following script: #!/usr/bin/perl -w @files = <*.csv>; foreach $file (@files) { open(FH, $file); my @dt = split(/_|.csv/, $file); while (<FH>) { chomp; print $dt . $dt . ",$_\n"; } close(FH); } This script reads in all csv files in the current directory... (2 Replies)
Discussion started by: figaro
2 Replies

10. Shell Programming and Scripting

HTML parsing by PERL

i have a HTML report file..its in attachment(a part of the whole report is attached..name "input html.doc").also its source is attached in "report source code.txt" i just want to seperate the datas like in first line it should be.. NHTEST-3848498958-NHTEST-10.2-no-baloo a and so on for whole... (3 Replies)
Discussion started by: avik1983
3 Replies
Login or Register to Ask a Question