[HPADM] SUMMARY:Perl or Hexdump question

From: Wouter (drempeltje@softhome.net)
Date: Thu Apr 10 2003 - 15:11:58 EDT


Hi,

Thanx to Ed who said: search with Google on "byte ascii nibble routine".

I found some interesting programs which do the same as od -x.
In that programs there was the unpack() command.

I tried the pack() command and that was exactly what i was looking for.
This short program is the solution:

open IN,"ASCII.TXT" or die;
open OUT,">>HEX.DAT" or die;
my $line;
my $convert;
my @read = <IN>;
foreach my $line (@read) {
   $line =~ s/\ //g;
   $convert = pack ("H32", $line);
   print OUT $convert;
}
---- END ----
hexedit HEX.DAT looks the same than the input.

Regards,
Wouter van Til

----- Original Message -----
From: "Wouter" <drempeltje@softhome.net>
To: "hpux" <hpux-admin@dutchworks.nl>
Sent: Sunday, March 16, 2003 22:04
Subject: [HPADM] Perl or Hexdump question

> Hi,
>
> This is not really a HPUX question but I try it anyway.
> I have a nice unix-job, it must be very simple but i can't come till a
> simple solution.
>
> The problem is:
> I want to convert a textfile to a normal file.
> I have the following input in a textfile:
> 52 65 05 00 ab 20 31 30 30 30 00 6a 65 0a 00 9f
> 20 31 36 2c 36 38 3a a0 20 9d 20 88 20 31 30 30
> 30 30 00 8a 65 0f 00 54 31 24 ca e6 28 32 33 29
> bd e6 28 31 30 29 bd e6 28 31 38 30 29 bd e6 28
> 30 29 00 aa 65 19 00 54 32 24 ca e6 28 32 33 29
> bd e6 28 31 30 29 bd e6 28 31 32 30 29 bd e6 28
>
> I want to convert this to a file with hexadecimal the same output as
above,
> so if i open the converted file in a hexeditor it has to look like the
file
> above.
>
> I think this is maybe possible with the hexdump command.
> Of course it is possible with a perl program.
> I started with a program, it reads the textfile and strips out the
> whitespace and CR/LF.
> But if i create a file with open OUT,"test.hex" or die; and i print
the
> hex-characters to it, they are in ASCII again.
>
> Does somebody can give me a hint or solution?
>
> Regards,
> Wouter van Til

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:28 EDT