Hex Dump SUMMARY

sean@nmc13.chinalake.navy.mil
Mon, 20 Oct 1997 15:31:19 -0700

This is a multi-part message in MIME format.

--Boundary_(ID_jbdQbjrW1TwNxjrnrjdD3Q)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7bit

-- 
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
                                                            
  Sean Harvey   OAO Corp  harvey@nmc8.chinalake.navy.mil  
     Ridgecrest CA  (619)939-2199                           
                                                            
	a Million dollars a day!!
       Dammit  Janet, I love you!!       
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

--Boundary_(ID_jbdQbjrW1TwNxjrnrjdD3Q) Content-type: text/plain; name=HEX_summary; charset=us-ascii Content-disposition: inline; filename=HEX_summary Content-transfer-encoding: 7bit

ORIGINAL QUESTION:

>Hello All- > >I need to view ascii files in hex format on a Sun workstation. Similar >to what Norton Utilities will do on a PC. Can anyone tell me how? > >Sean

I recieved many replies saying 'use od'. I did, it worked, thanks.

Here are a couple of perl scripts:

>From Darren Brechman-Toussaint

======================== cut here ================================ #!/opt/perl/perl

# Usage: xdump [file]

# Use the file they specified, if specified

open(STDIN,$ARGV[0]) || die "Can't open $ARGV[0]: $!\n" if $ARGV[0];

# Do it optimall as long as we can read 16 bytes at a time.

while (($len = read(STDIN,$data,16)) == 16) { @array = unpack('N4', $data); $data =~tr/\0-\37\177-\377/./; printf "%8.08x %8.08x %8.08x %8.08x %8.08x %s\n",$offset, @array, $data; $offset += 16; }

# Now finish up the end a byte at a time.

if ($len) { @array = unpack('C*', $data); $data =~y/\0-\37\177-\377/./; for (@array) { $_ = sprintf('%2.2x', $_); } push(@array, ' ') while $len++ < 16; $data =~ s/[^ -~]/./g; printf "%8.08x ",$offset; printf "%s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s %s\n",@array, $data; }

============================================================

From: David Thorburn-Gundlach

Here ya go. A budding perl hacker, I whipped up a script for you :-) I'd be interested in a summary...

###################################################################### # hexdump: writes an annoted hex dump of the form # hexx addr: hx hx hx hx hx hx hx ... hx aaaaaaa...a # control chars (octal 0-37 + 177) are converted to '.' (KISS principle) ######################################################################

# $Id: hexdump,v 1.1 1997/10/09 17:29:42 dtg11111 Exp $ #

# I should put a Usage() in here in case of problems... $input_file = $ARGV[0]; # must read from file(?) $file_pos = 0; # offset = 0 (beginning)

open (INPUT_FILE, $input_file) || die ("Whoa! Could not open $input_file!\n");

$line_text = sprintf ("%8lx", $file_pos); # line begin hex address $line_text =~ s/ /0/g; # convert ' ' to 0 $line_text =~ s/^(....)/$1 /g; # break word into bytes $line_text .= ": "; # spacing for data

$hex_string = ""; # string to read $sixteen_bytes = ""; ###

# Grab each 16-byte segment in file, increment file position. while (read (INPUT_FILE, $asc_string, 16) == 16) # more file to process? { $file_pos += 16; # track for counter $hex_string = unpack ("H32", $asc_string); # asc2hex $hex_string =~ s/(..)/$1 /g; # hxhx => hx hx $asc_string =~ s/([\00-\37,\177])/./g; # strip ctrl chars $line_text .= "$hex_string"; # put together $line_text .= " $asc_string"; # put together print "$line_text\n"; # show the line

$line_text = sprintf ("%8lx", $file_pos); # line begin hex address $line_text =~ s/ /0/g; # convert ' ' to 0 $line_text =~ s/^(....)/$1 /g; # break word into bytes $line_text .= ": "; # spacing for data }

close (INPUT_FILE);

--Boundary_(ID_jbdQbjrW1TwNxjrnrjdD3Q)--