//View Tip #498
Similar Tips
» Rename many files using find and perl
» An interactive perl shell
» Using comm
» Moved Trac and Subversion repositories to another machine/direct
» Replace expr by other recursively

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
This script displays the contents of files (or stdin) in ascii, hexadecimal, decimal, octal, and binary formats.


#!/usr/bin/perl undef $/; # slurp files while( $content = <> ) { $offset = 0; print "OFFSET ASC HEX DEC OCT BIN\n"; while( length $content ) { $n = ord( substr( $content, 0, 1, '' ) ); printf "%08x %c %2x %3u %3o %s\n" , $offset, , ( $n > 0x1f && $n < 0x7f ) ? $n : ord '.', , $n, , $n, , $n, , substr( unpack( "B*", pack( "n", $n ) ), -8 ) ; $offset++; } }



View Comments »




Comments 

Add your comment

Comments are currently disabled
nvb
hey shed style
Posted 2009-06-27 16:31:38
Charles
That's an awful lot of work for something that can already be done better using od
Posted 2010-06-17 13:30:04

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit