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 data7data data data da +ta data8 +  + +7 Page 1 +8[3;23 data data data: data data data data, +data data: data data data data data data 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;


In reply to How to parse out unwanted characters in a text file using Perl by mizmaster22

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.