• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1144
  • Last Modified:

Print hex as ascii to a file

Please note this is actually a bash script, but the line I need fixed (shown below) is in perl
all other lines removed to  make it simple.

#!/bin/bash

DATACODE="012 061 062 063 101 104 105 107 110 111 115 116 124 127 131"

for i in $DATACODE ; do
perl print chr($i) > output.txt ;
done
0
ALEx604
Asked:
ALEx604
  • 2
  • 2
  • 2
1 Solution
 
gripeCommented:
#!/bin/bash

DATACODE="012 061 062 063 101 104 105 107 110 111 115 116 124 127 131"

for i in $DATACODE ; do
echo $i
perl -e"print chr($i)" >> output.txt ;
done
0
 
ALEx604Author Commented:

Thanks...
you forgot a space between the -e and "

;)

ALEx
0
 
gripeCommented:
It was intentional.. you don't need one.

;)
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
ozoCommented:
Is $DATACODE hex or octal or decimal?
0
 
ALEx604Author Commented:
ozo asked:
> Is $DATACODE hex or octal or decimal?

$DATACODE is a variable I made in unix bash. The actual variables within it are hex output from a hexdump. (altered after something else within the script not shown.)

gripe point out: (in reference to the space)
>  It was intentional.. you don't need one.

Actually I did. It didn't work without it. I'm using Gnubash which is why I think.
0
 
ozoCommented:
"print chr($i)" will interpret 012 as octal and 101 as decimal.
if you want hex, you could use something like
perl -e 'print pack"C*",map{hex}@ARGV' $DATACODE
although 101 will be the same character as 01
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now