#!/usr/bin/perl -w # reverse_xxd.pl - Don Yang (uguu.org) # # This script is for people who don't have xxd installed, otherwise it # does mostly the same thing as "xxd -r". # # Reads text data from stdin and writes binary data to stdout. # # 2013-06-05 use strict; while( my $line = <> ) { next unless $line =~ /^\d+:([[:xdigit:] ]*)/; my $digits = $1; # Decode 2 bytes at a time my $output = ""; while( $digits =~ s/^ ([[:xdigit:]]{2})([[:xdigit:]]{2})(.*)/$3/ ) { $output .= chr(hex($1)) . chr(hex($2)); } # Decode the last byte if( $digits =~ /^ ([[:xdigit:]]{2})/ ) { $output .= chr(hex($1)); } print $output; }