This worked for me.

$ echo -n 54657374696e672031203220330 | xxd -r -p
Testing 1 2 3$

echo -n prevents a newline from being added to the end

-r tells it to convert hex to ascii as opposed to its normal mode of doing the opposite

-p tells it to use a plain format.

Answer from funroll on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ scripting โ€บ convert hex to ascii characters in the linux shell
Convert Hex to ASCII Characters in the Linux Shell | Baeldung on Linux
March 18, 2024 - The printf command formats and prints the data on the console. We can use this command to convert a character from hex to ASCII:
๐ŸŒ
Linux Handbook
linuxhandbook.com โ€บ convert-hex-ascii
Convert Hex to ASCII Characters in Linux Bash Shell
July 27, 2025 - Yes, you can convert hex to ASCII using the bash printf command.
Discussions

Ascii/Hex convert in bash - Stack Overflow
I'm now doing it this way: [root@~]# echo Aa|hexdump -v 0000000 6141 000a 0000003 [root@~]# echo -e "\x41\x41\x41\x41" AAAA But it's not exactly behaving as I wanted,... More on stackoverflow.com
๐ŸŒ stackoverflow.com
bash - How to convert hex to ASCII characters in the Linux shell? - Stack Overflow
Let's say that I have a string 5a. This is the hex representation of the ASCII letter Z. I need to find a Linux shell command which will take a hex string and output the ASCII characters that the hex More on stackoverflow.com
๐ŸŒ stackoverflow.com
Bash. Hex to ascii. Is possible without xxd or perl? - Stack Overflow
I'm developing a script on which I have a hex string 31323334353637383930313233 and I want to transform it into ASCII. Desired output is 1234567890123. I already have it working using: echo " More on stackoverflow.com
๐ŸŒ stackoverflow.com
March 16, 2017
Convert column from hex to ascii
I can modify the column using awk but I can't pass that value to another command to do the convertion. Either you can do whatever you want, or this is homework. If so, please say so. Next, is this a Bash-only assignment, or can you use other languages? This is easy to do, but it would be much easier if you would post the assignment's hexadecimal source so I could show the conversion of your example text. Meanwhile, here's a sample: #!/usr/bin/env bash ascii="" for c in 54 68 69 73 20 69 73 20 61 20 74 65 73 74 2e; do ascii+="\x$c" done echo -e $ascii Output: This is a test. More on reddit.com
๐ŸŒ r/bash
21
5
July 25, 2019
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ linux-how-to-convert-hex-to-ascii-in-bash-431151
How to convert hex to ASCII in bash | LabEx
## Convert hex to ASCII echo -n "48 65 6c 6c 6f" | xxd -r -p ## Output: Hello ## Convert ASCII to hex echo -n "Hello" | xxd -p ## Output: 48656c6c6f
๐ŸŒ
UbuntuMint
ubuntumint.com โ€บ home โ€บ linux commandline tips โ€บ how to convert hex to ascii characters in linux
How to Convert Hex to ASCII Characters in Linux
July 24, 2023 - We mainly use the xxd command to ... stated action. Firstly, an echo command will take the sample Hex characters as inputs before piping them to the xxd command for for conversion to ASCII characters....
๐ŸŒ
DEV Community
dev.to โ€บ carlyraejepsenstan โ€บ converting-hex-to-text-the-bash-way-1483
Converting Hex to Text - the Bash Way - DEV Community
March 18, 2022 - Next, we know that you can convert a hex byte into ASCII (or text) by using echo like this:
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ convert-hex-to-ascii-characters-in-the-linux-shell
Convert Hex to ASCII Characters in the Linux Shell
March 17, 2026 - Converting hex to ASCII in Linux can be accomplished through multiple command-line tools, each with distinct advantages. The printf and xxd methods are most straightforward for simple conversions, while perl and sed offer more flexibility for complex pattern processing.
Top answer
1 of 5
4

Found this script here:

#!/bin/bash
function hex2string () {
  I=0
  while [ $I -lt ${#1} ];
  do
    echo -en "\x"${1:$I:2}
    let "I += 2"
  done
}
hex2string "31323334353637383930313233"
echo

You may change the line hex2string "31323334353637383930313233" so that it takes the hex value from parameters, that is:

#!/bin/bash
function hex2string () {
  I=0
  while [ $I -lt ${#1} ];
  do
    echo -en "\x"${1:$I:2}
    let "I += 2"
  done
}
hex2string "$1"
echo

So when executed as:

./hexstring.sh 31323334353637383930313233

It will provide the desired ascii output.

NOTE: Can't test if it works in all Linux systems.

2 of 5
4

Using gawk, from HEX to ASCII

$ gawk  '{ 
           gsub(/../,"0x& "); 
           for(i=1;i<=NF;i++)
              printf("%c", strtonum($i)); 
           print "" 
}' <<<"31323334353637383930313233"
1234567890123

Using any awk

$ cat hex2asc_anyawk.awk 
BEGIN{
    split("0 1 2 3 4 5 6 7 8 9 A B C D E F", d, / /)
    for(i in d)Decimal[d[i]]=i-1
}

function hex2dec(hex,  h,i,j,dec)
{ 
    hex = toupper(hex);                
    i   = length(hex);                 
    while(i)
    {  
          dec += Decimal[substr(hex,i,1)] * 16 ^ j++
          i--                          
    }
    return dec;
}
{

    gsub(/../,"& "); 
    for(i=1;i<=NF;i++)
        printf("%d",hex2dec($i));
    print ""
}

Execution

$ awk -f hex2asc_anyawk.awk <<<"31323334353637383930313233"
1234567890123

Explanation

Steps :

  1. Get the decimal equivalent of hex from table.

  2. Multiply every digit with 16 power of digit location.

  3. Sum all the multipliers.

Example :

BEGIN{
    # Here we created decimal conversion array, like above table
    split("0 1 2 3 4 5 6 7 8 9 A B C D E F", d, / /)
    for(i in d)Decimal[d[i]]=i-1
}

function hex2dec(hex,  h,i,j,dec)
{ 
    hex = toupper(hex);                 # uppercase conversion if any A,B,C,D,E,F
    i   = length(hex);                  # length of hex string
    while(i)
    {  
          # dec var where sum is stored
          # substr(hex,i,1) gives 1 char from RHS
          # multiply by 16 power of digit location 
          dec += Decimal[substr(hex,i,1)] * 16 ^ j++
          i--                           # decrement by 1
    }
    return dec;
}
{
    # it modifies record
    # suppose if given string is 31323334353637383930313233
    # after gsub it becomes 31 32 33 34 35 36 37 38 39 30 31 32 33
    # thus re-evaluate the fields

    gsub(/../,"& "); 

    # loop through fields , NF gives no of fields
    for(i=1;i<=NF;i++)

        # convert from hex to decimal
        # and print equivalent ASCII value 
        printf("%c",hex2dec($i));

    # print newline char
    print ""
}

Meaning of dec += Decimal[substr(hex,i,1)] * 16 ^ j++

dec += Decimal[substr(hex,i,1)] * 16 ^ j++
 ^           ^                    ^
 |           |                    | 
 |           |                    2.Multiply every digit with 16 power of digit location.
 |           |    
 |           1.Gives decimal equivalent of hex
 | 
 | 
 3. Sum all the multipliers 
๐ŸŒ
Unix Community
community.unix.com โ€บ shell programming and scripting
Converting hex to ascii/decimal - Shell Programming and Scripting - Unix Linux Community
March 31, 2011 - I am writing a bash script to do some parsing on a log and I am running into a problem when it comes to converting only certain sections of the file from hex to ascii or hex to decimal. Data Example: The hex values after Hardware and SW Version I need to convert from Hex to ASCII and the Errors, Full, Test values I need to convert from hex to decimal.
๐ŸŒ
SysTutorials
systutorials.com โ€บ convert-hex-to-ascii-using-xxd
Converting Hex To ASCII With Xxd - SysTutorials
April 12, 2026 - For simple one-liners, printf with bash parameter expansion works for small inputs: ... For larger data or programmatic use, stick with xxd. For complex binary manipulation, consider od, hexdump, or scripting in Python with bytes.fromhex(). The xxd -r -p combination remains the fastest and ...
๐ŸŒ
Reddit
reddit.com โ€บ r/bash โ€บ hex to ascii conversion - noob question
r/bash on Reddit: Hex to ASCII conversion - noob question
December 12, 2024 -

Hi all, freshly joined noobie here :)

I am currently working as a jr embedded software engineer, and have been struggling with data collection at runtime of the application.
I'm using a debugger that keeps sending a variable's hex value to the host pc via usb, but since this value is interpreted as ASCII, I see invalid symbols on the terminal.

As naive as it may sound, my question is: is there a way with a script to "get in between" the debugger and the terminal on the host pc to convert these hex values in their ASCII counterpart, so they are displayable "correctly"? (like, if I send 0x0123 I'd like the terminal to show "291" instead of the symbols associated with 0x01 and 0x23).
Extra question: do you have any suggestion on material I can study on to get a solid knowledge of bash scripting in general, too?

Thank you for your time and your patience, I hope I didn't sound too stupid haha.

๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ scripting โ€บ how to convert a string to hexadecimal on the command line in linux
How to Convert a String to Hexadecimal on the Command Line in Linux | Baeldung on Linux
March 18, 2024 - We can see that xxd shows output in three columns. Firstly, it shows the offset of data in the leftmost column. Then after, it shows the hexadecimal value, and in the rightmost column, it shows the ASCII value of the text.
Top answer
1 of 7
25

Hex:

printf '\x4a'

Dec:

printf "\\$(printf %o 74)"

Alternative for hex :-)

xxd -r <<<'0 4a'
2 of 7
10

In general, the shell could understand hex, oct and decimal numbers in variables, provided they have been defined as integers:

$ declare -i v1 v2 v3 v4 v5 v6 v7
$ v1=0112
$ v2=74
$ v3=0x4a
$ v4=8#112
$ v5=10#74
$ v6=16#4a
$ v7=18#gg
echo "$v1 $v2 $v3 $v4 $v5 $v6 $v7"
74 74 74 74 74 74 304

Or they are the result of an "Arithmetic Expansion":

$ : $(( v1=0112, v2=74, v3=0x4a, v4=8#112, v5=10#74, v6=16#4a, v7=18#gg ))
$ echo "$v1 $v2 $v3 $v4 $v5 $v6 $v7"
74 74 74 74 74 74 304

So, you just need one way to print the character that belongs to a variable value.
But here are two possible ways:

$ var=$((0x65))
$ printf '%b\n' "\\$(printf '0%o' "$var")"
e

$ declare -i var
$ var=0x65; printf '%b\n' "\U$(printf '%08x' "$var")"
e

The two printf are needed, one to transform the value into an hexadecimal string and the second to actually print the character.

The second one will print any UNICODE point (if your console is correctly set).
For example:

$ var=0x2603; printf '%b\n' "\U$(printf '%08x' "$var")"
โ˜ƒ

An snow man.

The character that has an utf-8 representation as f0 9f 90 ae is 0x1F42E. Search for cow face site:fileformat.info to get it:

$ var=0x1F42F; printf '%b\n' "\U$(printf '%08x' "$var")"
๐Ÿฎ

Note: There is a problem with the UNICODE way in that for bash before 4.3 (corrected in that version and upwards), the characters between UNICODE points 128 and 255 (in decimal) may be incorrectly printed.


References

Fourth paragraph inside PARAMETERS in man bash:

If the variable has its integer attribute set, then value is evaluated as an arithmetic expression even if the $((...)) expansion is not used (see Arithmetic Expansion below).

Inside "ARITHMETIC EVALUATION" in man bash:

Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the form [base#]n, where the optional base is a decimal number between 2 and 64 representing the arithmetic base, and n is a number in that base. If base# is omitted, then base 10 is used. The digits greater than 9 are represented by the lowercase letters, the uppercase letters, @, and _, in that order. If base is less than or equal to 36, lowercase and uppercase letters may be used interchangeably to represent numbers between 10 and 35.