made a program that uses a file as input and sort the characters inside the file.
file4="temp.txt"
name4=$(cat $file4)
echo $name4 | sed 's/\(.\)/\1\n/g' > file4.txt
echo "enter how many rows :"
read cols
IFS=$'\n' a=($(cat file4.txt))
for j in $(seq ${#a[*]}); do
[[ ${a[$j-1]} = $name ]] && echo "${a[$i]}"
done
for (( i=0; i<=$(( ${#a[@]} / cols )); ++i )); do
for (( j=0; j<cols; ++j )); do
if (( i%2 )); then idx=$(( (i + 1) / 2 * 2 * cols - j - 1 ))
else idx=$(( (i / 2) * 2 * cols + j )); fi
printf "%-4s " "${a[idx]}"
done
printf "\n"
done
i got this output.
Output:
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
18 17 16
and i wanted to save it in a single line string and into a file. the problem now is it should be sorted like this
1 10 11 12 9 2 3 8 13 18 17 14 7 4 5 6 15 16
i googled and what im getting is it save in right to left order
1 2 3 4 5 10 9 8 .....
any idea how?