The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: parsing variables figaro Shell Programming and Scripting 2 07-16-2008 10:53 AM
xml parsing error in perl bishweshwar UNIX for Advanced & Expert Users 1 05-30-2007 10:59 PM
HTML parsing by PERL avik1983 Shell Programming and Scripting 3 02-23-2007 09:25 AM
PERL - Parsing Crystal Reports srinivay Shell Programming and Scripting 0 05-12-2005 07:55 AM
Conversion of bash parsing script to perl? cstovall Shell Programming and Scripting 2 10-13-2004 10:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-06-2008
popeye popeye is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 25
Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w
$ip = "$ARGV[0]";
$rw = "$ARGV[1]";
$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
IOS (tm) 7200 Software (C7200-JK9O3S-M), Version 12.3(22), RELEASE SOFTWARE (fc2)
Technical Support: Cisco - Shortcut
Copyright (c) 1986-2007 by cisco Systems, Inc.
Compiled Wed 24-Jan-07 2
sysObjectID.0 = OID: enterprises.9.1.222
sysUpTime.0 = Timeticks: (122783188) 14 days, 5:03:51.88
sysContact.0 = STRING: 1265108
sysName.0 = STRING: nameoftherouter
sysLocation.0 = STRING: someplace, ny
sysServices.0 = INTEGER: 78
sysORLastChange.0 = Timeticks: (0) 0:00:00.00
ifNumber.0 = INTEGER: 10
ifIndex.1 = INTEGER: 1
ifIndex.2 = INTEGER: 2


In ksh to get the Version number and hostname I would do something like

vers=`echo "$syst" | grep -i version | sed 's/.*ersion //' | cut -d"," -f1`
hnam=`echo "$syst" | grep sysName | head -1 | sed 's/.*RING: //' | cut -d"."
-f1`

what is perls equivalent ?
  #2 (permalink)  
Old 08-06-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Something like this?

Code:
if ($syst =~ /Version ([^,]+),/) { $version=$1; } else { $version="unknown"; }
if ($syst =~ /sysName.*STRING: (.+)/) { $hnam=$1; } else { $hnam="unknown"; }
print "$version\n$hnam\n";
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0