2

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 ?

user3719454
  • 994
  • 1
  • 9
  • 24
  • 1
    General computer usage is not suitable for Stack Overflow. The most portable solution is to use shell builtins instead of `xxd`; try e.g. `printf '\xe2\x80\x99\n'` – tripleee Mar 21 '22 at 11:24
  • 1
    Possible duplicate of https://stackoverflow.com/questions/9604270/hexadecimal-escapes-to-textutf-8-bash-script – tripleee Mar 21 '22 at 11:25

2 Answers2

3

I suggest:

echo 'e28099' | xxd -r -p

Output:

Cyrus
  • 84,225
  • 14
  • 89
  • 153
0
$ 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 $_.)

ikegami
  • 367,544
  • 15
  • 269
  • 518