xxd: how to simply revert without adding "00000000:"?

428 Views Asked by At

Sometimes I have unwanted characters in my files (DB tables, git content, etc). When I list them with xxd I have the UTF-8 code, e.g.:

e28099

I would like to know which is this character in bash, so I type:

echo -n '00000000: e28099' | xxd -r

And I will have

on the console. Is it possible not to include always those zeroes (00000000: )? So are there any params of xxd with which I could type:

echo -n 'e28099' | xxd -??? and the result will be ?

2

There are 2 best solutions below

0
On BEST ANSWER

I suggest:

echo 'e28099' | xxd -r -p

Output:

0
On
$ perl -le'print pack "H*", $ARGV[0]' e28099
’
$ perl -Mv5.10 -Mcharnames=:full -C -e'
   $_ = pack "H*", $ARGV[0];
   utf8::decode $_;
   say;
   for my $cp ( unpack "W*", $_ ) {
      my $c = chr( $cp );
      say sprintf "%s U+%X %s",
         ( $c =~ /\p{Print}/ && !/\p{Mark}/ ) ? "[$c]" : "   ",
         $cp,
         charnames::viacode( $cp );
   }
' e28099
’
[’] U+2019 RIGHT SINGLE QUOTATION MARK

(To make them use STDIN instead of an argument, replace -le/-e with -ple, and replace $ARGV[0] with $_.)