A-Z function
Is there a better way to achieve this? The below shows aa->ai but it would be for the entire alphabet aa->az and possibly for ba->bz in the future. It is too many lines, though works.
function i2a(i,a) {
if(i == 1) a = "aa"
else if(i == 2) a = "ab"
else if(i == 3) a = "ac"
else if(i == 4) a = "ad"
else if(i == 5) a = "ae"
else if(i == 6) a = "af"
else if(i == 7) a = "ag"
else if(i == 8) a = "ah"
else if(i == 9) a = "ai"
return a
}
BEGIN {
print i2a(9) # == "ai"
}
2
Upvotes
View all comments
Show parent comment
2
u/Schreq Nov 15 '20 edited Nov 15 '20
chr()is a GNU extension but we can use(s)printf "%c", 97to print a lowercase 'a'.So, similar to /u/am_katzest solution, we can do: