batch sort a CSV file by increasing number

Microsoft Upg-vc msdos 6.22
November 25, 2010 at 01:54:48
Specs: Windows 2003
Hello,
I absolutely need to work this out with a dos batch file:

"user_id","city","full_name",..............
"12","new york","Tom Waits",............
"30","springfield","Anita Franklin",.......
"4","timoara","Bill Gates",........

I need the output to be

"user_id","city","full_name",..............
"4","timoara","Bill Gates",........
"12","new york","Tom Waits",............
"30","springfield","Anita Franklin",.......

sorted by increasing number in column 1 "user_id"

Would you help me?
Thank you very much indeed!


See More: batch sort a CSV file by increasing number

Report •

#1
November 25, 2010 at 03:24:54
How high do the numbers go?


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 25, 2010 at 03:29:00
If the first column is text (as it appears to be) it may sort as 12, 30, 4. There are DOS sort utilities that can sort CSV files using various parameters.

Report •

#3
November 25, 2010 at 06:45:17
numbers will never get higher than 99999

okok and what about some code to do the job?


Report •

Related Solutions

#4
November 26, 2010 at 22:05:49
@echo off > newfile & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (my.csv) do (
> new.csv echo.%%a
goto :next
)
:next

for /f "skip=1 tokens=1* delims=," %%a in (my.csv) do (
set A=%%a
set A=!A:"=!
call :sub1
>> newfile echo."!N!", %%b
)

sort < newfile > sorted & type sorted >> new.csv

goto :eof

:sub1
if !A! lss 10000 set N=0!A!
if !A! lss 1000 set N=00!A!
if !A! lss 100 set N=000!A!
if !A! lss 10 set N=0000!A!

goto :eof


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question