How to sort lines of a text file containing version numbers in format major.minor.build.revision numerical?

后端 未结 5 736
忘掉有多难
忘掉有多难 2020-12-04 04:06

I have a txt file with values like this:

3.6.4.2
3.6.5.1
3.6.5.10
3.6.5.11
3.6.5.12
3.6.5.13
3.6.5.2
3.6.7.1
3.6.7.10
3.6.7.11
3.6.7.2
3.6.7.3
5条回答
  •  鱼传尺愫
    2020-12-04 04:17

    Based on your example this will work. If you should somehow end up with examples like 3.6.5.02 and 3.6.5.2, then this code will not work.

    @echo off
    setlocal EnableDelayedExpansion
    for /F "tokens=1-4 delims=. " %%G in (FILE.TXT) do (
       set N=0%%J
       set SORT[%%G%%H%%I!N:~-2!]=%%G.%%H.%%I.%%J
    )
    for /F "tokens=2 delims==" %%N in ('set SORT[') do echo %%N
    
    pause
    

提交回复
热议问题