would you write a batch script/ Batch file for windows ( file.bat) to sort by column for a table this script will be able to show to the user a few options. the user will choose between : sort i | n | w | l | c | a| i for id , n for name , w for weight , l for long , c for class , a for age. The textfile : ID Name Weight Long Class Age 012 Eric 56 156 7 13 045 Richard 78 178 9 17 098 Maya 60 164 10 16 072 Anna 56 152 8 14 034 Helena 76 169 11 18 022 Kevin 66 162 6 12 093 Peter 99 170 12 19
would you write a batch script/ Batch file for windows ( file.bat) to sort by column for a table
this script will be able to show to the user a few options.
the user will choose between :
sort i | n | w | l | c | a|
i for id , n for name , w for weight , l for long , c for class , a for age.
The textfile :
ID Name Weight Long Class Age
012 Eric 56 156 7 13
045 Richard 78 178 9 17
098 Maya 60 164 10 16
072 Anna 56 152 8 14
034 Helena 76 169 11 18
022 Kevin 66 162 6 12
093 Peter 99 170 12 19
I tried this under but didn't work for windows , it work for shell script and i need for batch script
echo "Sort the file by column: "
echo "choose from below to sort"
echo "i | n | w | l | c | a"
read input
ID_colnum=1
Name_column=2
Weight_column=3
long_column=4
class_column=5
age_column=6
case $input in
"i")head -n 1 data.txt && tail -n +2 data.txt | sort -k $ID_colnum;;
"n")head -n 1 data.txt && tail -n +2 data.txt | sort -k $Name_column;;
"w")head -n 1 data.txt && tail -n +2 data.txt | sort -k $weight_column;;
"l")head -n 1 data.txt && tail -n +2 data.txt | sort -k $long_column;;
"c")head -n 1 data.txt && tail -n +2 data.txt | sort -k $class_column;;
"a")head -n 1 data.txt && tail -n +2 data.txt | sort -k $age_column;;
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images