windows - How to sort csv by columns using batch scripting? -


i have csv file in following format:

column1,column2,column3 2,1,0 1,0,0 3,2,0 1,4,1 4,3,0 1,1,4 5,6,0 6,5,0 

i want sort 1st , 3rd columns using bat file. result want is:

column1,column2,column3 1,0,0 1,4,1 1,1,4 2,1,0 3,2,0 4,3,0 5,6,0 6,5,0 

in unix can done using sort -n -k1,1 -k3,3 xx.csv > sorted.csv. tried sort /+1 /+3 xx.csv > sorted.csv in windows, didn't work... help

perhaps simplest , fastest way achieve this:

@echo off setlocal  set /p "header=" < input.txt echo %header% /f "skip=1 tokens=1-3 delims=," %%a in (input.txt) set a[%%a,%%c]=%%b /f "tokens=2-4 delims=[,]=" %%a in ('set a[') echo %%a,%%c,%%b 

output:

column1,column2,column3 1,0,0 1,4,1 1,1,4 2,1,0 3,2,0 4,3,0 5,6,0 6,5,0 

previous program assume there not records same column1 , column3, , contents of columns 1 digit. these limitations may fixed, if needed.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -