I have created a script that gets names and surnames of people both in latin and greek characters. My challenge was to translate all greek characters to latin ones in order to create more possible Facebook links to their profiles, but use only bash and nothing more, like python, ruby, etc.
I have created something like a hash table file, which looks like this (look below) and follows a simple rule... Each record is separated with comma, the 1st field represents the number of additional ways of expression a letter has, the 2nd field represents the greek letter I want to find and the next ones (3rd and/or 4th) represent how the greek letters are expressed in latin way.
0,Α,A
0,Β,B
0,Γ,G
0,Δ,D
0,Ε,E
0,Ζ,Z
0,Η,I
0,Θ,TH
0,Ι,I
0,Κ,K
0,Λ,L
0,Μ,M
0,Ν,N
1,Ξ,X,KS
0,Ο,O
0,Π,P
0,Ρ,R
0,Σ,S
0,Τ,T
1,Υ,Y,U
1,Φ,F,PH
1,Χ,CH,H
0,Ψ,PS
1,Ω,O,W
Now, after many hours of research, I haven't found anything that suits exactly my needs. What I've tried, with no success, is pass a string to the function, then the function loads each letter it has to translate from it's hashed table and it outputs it to a file called data.tr
function greek2latin()
{
#usage: greek2latin <string>
while read hashed
do
greek=$(echo $hashed | cut -d',' -f2)
latin0=$(echo $hashed | cut -d',' -f3)
echo $1 | tr '$greek' '$latin0' > "$PWD"/data/data.tr
#note that "1" is read as string, thus compared as one
#maybe I need to change that later on
if [ $(echo "$hashed" | cut -d',' -f1) == "1" ]
then
latin1=$(echo $hashed | cut -d',' -f4)
echo $1 | tr '$greek' '$latin1' > "$PWD"/data/data.tr
fi
done < "$PWD"/data/hashed.synonyms/greek2latin
}
Can someone tell my why it doesn't work as intended? I'd appreciate any help.
Thanks! :)