Im doing a school project where I need to sort a text file by columns chosen by the user using a batch script.
The file looks like this
ID Name Weight Length With Height
052 Chair 1200 100 30 2
077 Bookshelf 5000 120 30 80
096 Cabinet 15000 80 40 85
146 Cupboard 9000 80 60 200
149 Desk 3650 180 100 5
163 Mirror 25800 120 60 70
182 Table 1600 60 60 70
I tried copying the solution from this answer Batch sort by column in file
And modify it for 6 columns, code looks like this:
setlocal DisableDelayedExpansion
(
for /F "tokens=1-6 delims= " %%A in (%file%) DO (
set "par1=%%A"
set "par2=%%B"
set "par3=%%C"
set "par4=%%D"
set "par5=%%E"
set "par6=%%F"
setlocal EnableDelayedExpansion
echo(!par3! !par1! !par2! !par3! !par4! !par5! !par6!
endlocal
)
) > data.txt.tmp
for /F "usebackq tokens=1,* delims= " %%A in (`sort data.txt.tmp`) DO (
echo(%%B
)
So the problems im having is that I want the top row with ID Name etc to be unchanged. Second thing is this code works when sorting by ID and Name but when I get to weight for example it dosnt sort it correctly and i get output like this:
052 Chair 1200 100 30 2
096 Cabinet 15000 80 40 85
182 Table 1600 60 60 70
163 Mirror 25800 120 60 70
149 Desk 3650 180 100 5
077 Bookshelf 5000 120 30 80
146 Cupboard 9000 80 60 200
ID Name Weight Length With Height
Where it just seems to sort by first and second digit resulting in 15000 being put as smaller than 1600
How can i solve these problems in the best way?