-1

I wanted to convert the numbers from 1 to 26 to Latin alpgabet {a-z}. 1 correspnds to "a", and 2 to "b" and 26 to "z"

The following command only works for single digit numbers:

echo "$i" | tr 123456789 abcdefghi

for instance

echo "1" | tr 0123456789 abcdefghi

will produce "a"

How could you do it for :

echo "$i" | tr 01234567891011121314151617181920212223 abcdefghijklmnopqrstuvwxyz
choroba
  • 231,213
  • 25
  • 204
  • 289
Yacob
  • 515
  • 3
  • 10
  • 18

2 Answers2

1

tr only translates from one character to exactly one other character. You need to produce an expression via awk instead:

echo "$i" | awk 'chr($1+48)' # This only handles the numbers
echo "$i" | awk 'chr($1+87)' # This only handles lowercase

But note that this will not account for the specific pattern (0-9a-z) that you are looking for. You'll need to do more to separate the characters based on their ordinal ASCII value if you want it in a single expression.

heptadecagram
  • 908
  • 5
  • 12
-3

Hexadecimals can be echoed as easy as -e option

echo -e "\x41\x42\x43"

prints

ABC

How do you separate your integers? Do you understand that 11 can be interpreted as 11 or as 1,1?

Val
  • 1
  • 8
  • 40
  • 64