I have a string: Gatto piu bello anche cane in file. I am using awk to split it and to put it into array. But the output is not in the right order.
My code is:
while (getline < "'"$INPUTFILE"'") {
text = $0;
}
split (text,text_arr," ");
for (i in text_arr) {
print text_arr[i];
}
$INPUTFILE is file with that string.
But the output of this code is:
anche
cane
Gatto
piu
bello
I have no idea what's the problem.
(key in array)is undefined. Sometimes it will appear to be sorted; it is not guaranteed. The POSIX specification forawksays:for (variable in array)which shall iterate, assigning each index of array to variable in an unspecified order.