Perl parsing compared to Ksh parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl parsing compared to Ksh parsing
# 1  
Old 08-06-2008
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  
Old 08-06-2008
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";

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh parsing arguments in a string rather than from the cmdln

Hi. I have a piece of code that reads and parses command line options. I'd like to alter it slightly to read from a string (that's set elsewhere in the script) rather than directly from the command line (arg). Can somebody show me how to do this? Many thanks. My code is as follows: typeset... (6 Replies)
Discussion started by: user052009
6 Replies

2. Shell Programming and Scripting

Parsing ksh script

Is there any tool that can parsing ksh script into grammar format? e.g. the tool can parse the following ksh script: echo "hello"> abc.txt cp /home/user/abc/.profile /home/user/abc/myprofile into GENERATE abc.txt COPY /home/user/abc/.profile TO /home/user/abc/myprofile My server OS... (2 Replies)
Discussion started by: cstsang
2 Replies

3. UNIX for Advanced & Expert Users

Perl parsing help required.

Hello, I got a file like this. 5201 5202 5203 5204 1234 2345 3456 4567 6210 6220 6230 6240 The required output should be 5201 1234 6210 (9 Replies)
Discussion started by: suverman
9 Replies

4. Shell Programming and Scripting

XML parsing in KSH

Hi All, Although I was able to find past XML parsing questions, as the questions were a little different than this, I had a pretty hard time adapting those answers to this scenario. -> May I ask if anyone knows how to extract the IP addresses of the below "servers.xml" file into an array... (5 Replies)
Discussion started by: chatguy
5 Replies

5. Shell Programming and Scripting

Need help parsing config file in ksh

Hi all, I've done some searching here but haven't found exactly what I'm looking for so I thought I'd post up and see if someone can help out. I'm working on a shell script that I would like to store environment variables in an external file. I'm familiar with sourcing a file with variables in... (1 Reply)
Discussion started by: kungfusnwbrdr
1 Replies

6. Shell Programming and Scripting

help with ksh parsing traceroute output

Good day. I am doing an enq -WA (AIX), to get a list of the print queues, I then compare that to the /etc/hosts file to 'match' the IP address associated with the print queues. What I want to do is to run a traceroute with up to 5 hops, and perform an output to a file with some "specific items".... (0 Replies)
Discussion started by: smurphy_it
0 Replies

7. Shell Programming and Scripting

Perl Parsing Argument

i wanna passing an argument which read in a file or a set of files if the files are given in the command line, otherwise use STDIN if no file argument. i got something like that, but it is not really working. so can anyone help me? which one is better to use for and how? Use perl. Thank you ... (0 Replies)
Discussion started by: mingming88
0 Replies

8. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

9. Shell Programming and Scripting

Parsing and getting data from XML file using ksh script

Hi All, I have a xml file for example as described below <xml> <address> <street><street> <address/> <isbn>426728783932020308393930303</isbn> <book> <name> </name> </book> . . . </xml> My problem is to get the isbn number from the above described file using ksh script. Could... (6 Replies)
Discussion started by: vinna
6 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