computing
  • 3

Delete Last Line In CSV

  • 3

I need a batch file to delete the last line in every .csv file in a folder. I’ve seen serveral similar post, but nothing that works. Please helk!

Share

1 Answer

  1. All empty lines are ignored :

    @echo off
    setlocal enabledelayedexpansion

    set /a p_max=0

    for /F “tokens=*” %%a in (test.txt) do (
    set /a p_max=!p_max!+1
    )

    set /a cnt=1

    for /F “tokens=*” %%a in (test.txt) do (
    if !cnt! LSS %p_max% echo %%a
    set /a cnt=!cnt!+1
    )

    • 0