Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URRRRGH .. FRUSTATED .. PARSING

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US
if a $result contains the following, what is the best way to grab only 12.2(18)SXF8 ?

SNMPv2-MIB::sysDescr.0 = STRING: Cisco Internetwork Operating System Software
IOS (tm) s72033_rp Software (s72033_rp-ADVENTERPRISEK9_WAN-M), Version 12.2(18)SXF8, RELEASE SOFTWARE (fc2)
Copyright (c) 1986-2007 by cisco Systems, Inc.
 
Sorry forgot to give some code


$result =~ m/Version (.*)/;
@ver = split (/ /, $1);
print "$ver[0]\n";

Pretty crappy huh ??

 
Is this input from a file or some other source? What have you tried so far?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Code:
use strict;
use warnings;

my $stuff = "SNMPv2-MIB::sysDescr.0 = STRING: Cisco Internetwork Operating System Software
IOS (tm) s72033_rp Software (s72033_rp-ADVENTERPRISEK9_WAN-M), Version 12.2(18)SXF8, RELEASE 

SOFTWARE (fc2)
Copyright (c) 1986-2007 by cisco Systems, Inc. ";

$stuff =~ /Version\s+([^,]+)/;

print "$1\n";
seems to do it.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top