0

Tip #498   Create file dumps

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++; } }