Ekimino has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing an RTF File as plain text.
by chromatic (Archbishop) on Apr 08, 2012 at 04:46 UTC | |
by Ekimino (Novice) on Apr 08, 2012 at 05:16 UTC | |
Re: Parsing an RTF File as plain text.
by tangent (Parson) on Apr 08, 2012 at 00:06 UTC | |
Re: Parsing an RTF File as plain text.
by NetWallah (Canon) on Apr 08, 2012 at 00:14 UTC | |
by Anonymous Monk on Apr 08, 2012 at 04:03 UTC | |
by NetWallah (Canon) on Apr 08, 2012 at 04:57 UTC | |
Re: Parsing an RTF File as plain text.
by james2vegas (Chaplain) on Apr 08, 2012 at 09:21 UTC |
Back to
Seekers of Perl Wisdom