Batch to remove duplicate rows from text file

前端 未结 8 807
旧巷少年郎
旧巷少年郎 2020-11-29 10:37

Is it possible to remove duplicate rows from a text file? If yes, how?

8条回答
  •  一向
    一向 (楼主)
    2020-11-29 10:52

    set "file=%CD%\%1"
    sort "%file%">"%file%.sorted"
    del /q "%file%"
    FOR /F "tokens=*" %%A IN (%file%.sorted) DO (
    SETLOCAL EnableDelayedExpansion
    if not [%%A]==[!LN!] (
    set "ln=%%A"
    echo %%A>>"%file%"
    )
    )
    ENDLOCAL
    del /q "%file%.sorted"
    

    This should work exactly the same. That dbenham example seemed way too hardcore for me, so, tested my own solution. usage ex.: filedup.cmd filename.ext

提交回复
热议问题