I am trying to parse an RTF file as plain text, I have succeded in separating things, but I've been going around in circles with the output, which doesn't seem to work the way I want to. I think the abnormal behaviour comes from the RTF file. The output should go like this: $user:$hash . But it will only output $hash\n unless I separate them with a \t. Here goes the code:

#!/usr/bin/perl use strict; use warnings; chomp(my @file = <>); my @users; my @hashes; #sub listar{ # while(@file){ # if($_ =~ /Data Found/g){ # $_ =~ s/\\par//g; # $_ =~ s/Data Found: //g; # printf "$_\n"; # } # } #} # Separate Users and add each one @users. foreach(@file){ chomp $_; if($_ =~ /User=/g){ $_ =~ s/Data Found: //g; $_ =~ s/\\par//g; $_ =~ s/User=//g; unless($_ =~ /magela/){ push(@users, $_); } } } # Separate Hashes and add each one to array @hashes foreach(@file){ chomp $_; if($_ =~ /Pass=/g){ $_ =~ s/Data Found: //g; $_ =~ s/\\par//g; $_ =~ s/Pass=//g; push(@hashes, $_); } } pop @users; my $n = @users; printf "Numero de Usuarios: $n\n"; my $h = @hashes; printf "Numero de Hashes: $h\n"; my $f = 0; while($f < $n){ <b>printf "$users[$f]\t$hashes[$f]\n"</b>; $f += 1; }

Output with \t:

marianonc624d56fbf18eb79236e942c1478bc4e fermins 8e6c5623ad9a544731661e3f872bb5f2 monicar 1cf5bd31c0bf0cb33eae5d75adfc2094

Output without \t

:5c0b18186c48d9e29f773cca0939b9c1 :c624d56fbf18eb79236e942c1478bc4e :8e6c5623ad9a544731661e3f872bb5f2 :1cf5bd31c0bf0cb33eae5d75adfc2094

How I want it

username:hash

Before suspicious minds come along, Yes, this are passwords hashes from a VM inside my lab. How should I handle RTF without using a module? Thank you.


In reply to Parsing an RTF File as plain text. by Ekimino

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.