Convert a file of decimal numbers to the ASCII equivalent

54 Views Asked by At

I can convert a text file to a list of ASCII decimals like this:

$ echo "hello" | od -An -td1 -v -w1
  104
  101
  108
  108
  111
   10

What is the inverse operation? How can I convert the file of decimals back to text? I want to use only common Unix command-line tools. I've been looking at printf but haven't figured out how to make it work.

2

There are 2 best solutions below

2
On BEST ANSWER

you can use the printf function using the parameter "%c" that treats the input as a single character.

Easy solution: Pipe the output to the inverse function.

echo "hello" | od -An -td1 -v -w1 | awk '{ printf "%c", $1 }'

awk receives the piped information in the first column with ASCII value and sends it as input for the print function.

0
On
perl -ne'print( chr( $_ ) )'
perl -ne'print chr'
perl -pe'$_ = chr'

Specifying file to process to Perl one-liner