CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Parcing or Splitting data from Telnet output

 



pl3109
New User

Aug 26, 2015, 7:52 AM

Post #1 of 3 (1689 views)
Parcing or Splitting data from Telnet output Can't Post

Hello, I'm new here please pardon if posting in wrong section.

I have a script that I'm connecting to equipment, issuing commands and capturing response. I want to clean that data before dumping it to log. I don't know if I'm assigning array properly, but here is what I have:

Code
 
@check = $telnet->cmd(String=>$RTRVPM1);

$response = join(" ", @check);

print $response;


Response from command:

Code
    EQUIP-OME1 15-08-26 01:30:54 
M CTAG COMPLD
"OC48-1-14-2,OC48:OPRN-OCH,36,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"
"OC48-1-14-2,OC48:OPTN-OCH,97,COMPL,NEND,TRMT,1-DAY,08-25,00-00,1,,,,"
"ETH-1-13-1,ETH:INFRAMES-E,978758,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"
"ETH-1-13-1,ETH:OUTFRAMES-E,1057147,COMPL,NEND,TRMT,1-DAY,08-25,00-00,1,,,,"
>

EQUIP-OME1 15-08-26 01:30:55
M CTAG COMPLD
"OTM2-1-1-1,OTM2:OPR-OCH,-10.70,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"
"OTM2-1-1-1,OTM2:OPT-OCH,-6.50,COMPL,NEND,TRMT,1-DAY,08-25,00-00,1,,,,"
>

EQUIP-OME2 15-08-26 01:30:56
M CTAG COMPLD
"OTM2-1-3-1,OTM2:FEC-OTU,30181635949,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"
"OTM2-1-3-1,OTM2:PFBERE-OTU,1E-37,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"
"OTM2-1-3-1,OTM2:PRFBER-OTU,3.3E-05,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"

;
<

I want to print actual responses with data that start with " "" (Space Space Double Quote)
but also join equipment name to data comma separated. Do until ";" (semi colon).

Example output:

EQUIP-OME1,15-08-26,01:30:54,OC48-1-14-2,OC48:OPRN-OCH,36,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"
EQUIP-OME1,15-08-26,01:30:54,OC48-1-14-2,OC48:OPTN-OCH,97,COMPL,NEND,TRMT,1-DAY,08-25,00-00,1,,,,"
EQUIP-OME1,15-08-26,01:30:54,ETH-1-13-1,ETH:INFRAMES-E,978758,COMPL,NEND,RCV,1-DAY,08-25,00-00,1,,,,"
EQUIP-OME1,15-08-26,01:30:54,ETH-1-13-1,ETH:OUTFRAMES-E,1057147,COMPL,NEND,TRMT,1-DAY,08-25,00-00,1,,,,"
etc...

Any help is greatly appreciated.


Laurent_R
Veteran / Moderator

Aug 27, 2015, 6:55 AM

Post #2 of 3 (1656 views)
Re: [pl3109] Parcing or Splitting data from Telnet output [In reply to] Can't Post

Perhaps something like this (untested):

Code
my ($header, $line); 
while (<$IN>) {
next unless /^ "/;
chomp;
if (/^ (EQUIP-OM.+?\d\d$)/) {
print "$line\n";
$header = $1;
$line = $header; # start output line with $header
} else {
s/^\s{2}//; # remove white space at beginning
s/"//g; # remove quote marks
$line .= $_; # add new content to ourput line
}
}
print $line, "\n"; # print last line



FishMonger
Veteran / Moderator

Aug 27, 2015, 7:20 AM

Post #3 of 3 (1654 views)
Re: [Laurent_R] Parcing or Splitting data from Telnet output [In reply to] Can't Post

Cross posted on perlmonks.
http://perlmonks.org/?node_id=1140032

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives