使用命令将csv文件按三列sorting?

我读了很多文章在stackoverflow,但我仍然无法做sorting

情况是这样的:

我有一个没有标题的9列的csv文件,如下所示:

D,0000001,2016/01/01 01:00,111,0.000,0000008,10.000,NET,Computer B,0000002,2016/01/01 01:30,111,0.000,0000001,10.000,NET,Computer C,0000003,2016/01/01 02:00,121,0.000,0000001,10.000,ORG,Computer E,0000001,2016/01/01 02:00,121,0.000,0000003,10.000,ORG,Computer E,0000001,2016/01/01 02:00,121,0.000,0000003,10.000,COM,Computer C,0000001,2016/01/01 02:00,121,0.000,0000002,10.000,COM,Computer 

我想要的输出是2(000001),6(0000008),8(NET)列的顺序,并输出到新的csv文件,如下所示:

 C,0000001,2016/01/01 02:00,121,0.000,0000002,10.000,COM,Computer E,0000001,2016/01/01 02:00,121,0.000,0000003,10.000,COM,Computer E,0000001,2016/01/01 02:00,121,0.000,0000003,10.000,ORG,Computer D,0000001,2016/01/01 01:00,111,0.000,0000008,10.000,NET,Computer B,0000002,2016/01/01 01:30,111,0.000,0000001,10.000,NET,Computer C,0000003,2016/01/01 02:00,121,0.000,0000001,10.000,ORG,Computer 

我已经尝试了这样的代码,但不工作:

 @echo off setlocal for /F "tokens=1-9 delims=," %%a in (input.csv) do set a[%%b,%%a,%%c,%%d,%%e,%%f,%%g,%%h,%%i] =%% for /F "tokens=2-10 delims=[,]=" %%a in ('set a[') do echo %%b,%%a,%%c,%%d,%%e,%%f,%%g,%%h,%%i 

有人可以帮助我吗? 我是input命令脚本的新手。

你的方法很好。 只是字段值的顺序不正确设置为获得所需的输出排序顺序。

 @echo off if not exist input.csv goto :EOF setlocal for /F "tokens=1-9 delims=," %%a in (input.csv) do set "a[%%b,%%f,%%h,%%a,%%c,%%d,%%e,%%g,%%i]=%%" del input.csv for /F "tokens=2-10 delims=[,]=" %%a in ('set a[') do echo %%d,%%a,%%e,%%f,%%g,%%b,%%h,%%c,%%i>>input.csv endlocal 

这里创建的环境变量是%%b,%%f,%%h,%%a,%%c,%%d,%%e,%%g,%%i而不是%%b,%%a,%%c,%%d,%%e,%%f,%%g,%%h,%%i当然也需要%%d,%%a,%%e,%%f,%%g,%%b,%%h,%%c,%%i而不是%%b,%%a,%%c,%%d,%%e,%%f,%%g,%%h,%%i输出。

你几乎拥有它:

 @echo off setlocal for /F "tokens=1-9 delims=," %%a in (input.csv) do set "a[%%b%%f%%h]=%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i" for /F "tokens=2 delims==" %%a in ('set a[') do echo %%a 

但是,显示的结果并不像您在问题中所述的那样排序。 如果你想要%%f字段的%%f ,你可以使用这个:

 @echo off setlocal EnableDelayedExpansion for /F "tokens=1-9 delims=," %%a in (input.csv) do ( set /A "invF=100000000-1%%f" set "a[%%b!invF!%%h]=%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i" ) for /F "tokens=2 delims==" %%a in ('set a[') do echo %%a