I want to use the "cut" command to get some columns from a file, like this:
cat myfile | cut -f 5,3,2,1
The problem is that the output contains the columns I want, but in increasing order: 1,2,3,5, and not in the order I set before. I know I could also use awk, but for my shell script I do prefer to use "cut". Is there a way to solve this?
while read -a L
do
for i in 4 2 1 0 # indexes begin at 0
do echo -n ${L[$i]}
done
echo
done <myfile
or while read -a L
do echo "${L[4]} ${L[2]} ${L[1]} ${L[0]}"
done <myfile