I wrote a Perl script to log into my telnet server and send the output to a text file, but I am getting a ton of weird characters within each sentence of output that I want to parse\take out. All I want to do is read in the text file and remove the unwanted characters line by line to display the correct output.
EDIT:
Here are the first lines from my text file,the word data indicates the information I want and as you can see it is wrapped in the characters that I want to remove:
data data dat data data[1;1H[24;0H[K7[1;1H[0;7mdata data data da
+ta data[0m8[23;0H[0;7m
+ [0m[23;0H[2;1H[K[B[K[B[K[B
+[K[B[K[B[K[B[K[B[K[B[K[B[K[B[K[B[K[B[K[B[K[B[K
+[B[K[B[K[B[K[B[K[B[K[B[K[B7[1;65H[0;7m Page 1
+[0m8[3;1H[3;23
[5;1Hdata data [5;47Hdata: data data data data,
+data
[6;9Hdata: data
[7;4Hdata data data data [7;49Hdata data data data
HERE IS MY SCRIPT:(Which is working perfectly)
my ($hostname, $line, $password, $pop, $username);
$hostname = "local_host";
$username = "name";
$password = "pass";
$file = "log_file";
$file1 = "dump_log";
use Net::Telnet ();
$pop = new Net::Telnet (Telnetmode => 1, Input_log => $file, dump_log
+=> $file1);
$pop->open(Host => $hostname,Port => port#);
$pop->waitfor('/login: $/i');
$pop->print($username);
$pop->waitfor('/password: $/i');
$pop->print($password);
$pop->print("terminal type");
$pop->waitfor('/Command: $/i');
$pop->print("terminal_command");
$line = $pop->get;
print $line;
open FILE, "data.txt" or die $!;
print FILE $line;
close FILE;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.