SortFileBySecondColumn.bat
@echo off
if "%1"=="" (
echo Syntax: %0 FileToSort.txt [/R]
echo /R means Sort in Reverse Order
goto Ende
)
set InputFile=%1
for /f "tokens=1-2* delims= " %%a in ('(for /f "tokens=1-2* delims= " %%n in (%InputFile%^) do @echo %%o %%n %%p^)^|sort %2') do echo %%b %%a %%c
:Ende
Usage: SortFileBySecondColumn UnsortedFile.txt > SortedFile.txt
If you exchange delims=
by delims=;
then you can use it for CSV files.
Example Input file:
172.20.17.59 PC00000781 # 14.01.2022 12:35:55
172.20.17.22 NB00001021 # 31.01.2022 14:40:38
172.20.16.114 TRANSFER14 # 11.02.2022 11:22:07
10.59.80.27 PC00001034 # 14.02.2022 15:39:23
10.59.80.140 XXBNB00173 # 16.02.2022 10:13:31
172.20.17.23 PC00000XXX # 18.02.2022 12:40:58
10.59.232.25 NB00000178 # 18.02.2022 14:38:53
Resulting Output file:
10.59.232.25 NB00000178 # 18.02.2022 14:38:53
172.20.17.22 NB00001021 # 31.01.2022 14:40:38
172.20.17.59 PC00000781 # 14.01.2022 12:35:55
172.20.17.23 PC00000XXX # 18.02.2022 12:40:58
10.59.80.27 PC00001034 # 14.02.2022 15:39:23
172.20.16.114 TRANSFER14 # 11.02.2022 11:22:07
10.59.80.140 XXBNB00173 # 16.02.2022 10:13:31