Ok, i have sorted the letters by frequency, but how can i to do that the most bigger is "e", and to put that "e" into text?
#!/usr/bin/awk -f
function swapa(arr,i,j, tmp) {
tmp=arr;
arr=arr[j];
arr[j]=tmp;
}
function _qsort(arr,keys,i,j, k,i2,j2) {
if(j-i<1)
return
i2=i; j2=j;
# pivot, later algorithm depends on i here,
# so be careful if going to change it
k=arr[keys];
while(i2<j2) {
# push i2 to the right until there is k greater element
while(i2<=j && arr[keys[i2]]<=k) i2++;
# push j2 to the left until there is k less/equal element
while(j2>=i && arr[keys[j2]]>k) j2--;
if(i2<j2)
swapa(keys, i2, j2);
}
# if i2>j then there were no elements greater than k
# this is special case where we assume k as greatest element
# and place it to the end of the list
if(i2>j) {
swapa(keys, i, j);
i2--; j2--;
}
# recurse for subarrays
_qsort(arr, keys, i, j2);
_qsort(arr, keys, i2, j);
}
function qsort(arr,keys, n,i,k) {
for(k in arr) {
keys[++i] = k
}
n=i;
_qsort(arr, keys, 1, n);
return n;
}
BEGIN { FS="" }
{
for (i=1; i <= NF; i++) {
if ($i != " ")
letter[tolower($i)]++
}
}
END {
j = 1
for (i in letter) {
ind[j] = i
j++}
n=qsort(letter,ind);
for(i=1; i<=n; i++) {
print ind,letter[ind];
}
}