delete all lines of data except last line

August 25, 2011 at 13:46:45
Specs: Windows XP
delete all lines of data except last line from multiple files in a directory. Ex: I have 5 or more txt files in a directory with more lines of data. My requirement is to delete the lines of data from these txt files except the last line in the file. Only the last line has to be retained in the file. Please help me.

See More: delete all lines of data except last line

Report •


#1
August 26, 2011 at 19:41:13
Untested, change path to suit.

@echo off
cls
setlocal enabledelayedexpansion

pushd Path\To\Text\Files\||echo Pushd failed - job terminated.&&exit /b

for /f "tokens=*" %%1 in ('dir /b "*.txt"') do (
    set infile=%%1

        for /f "tokens=*" %%A in (!infile!) do (
            set inline=%%A
        )

     echo !inline!>"new !infile!"
)
popd


Please come back & tell us if your problem is resolved.


Report •
Related Solutions


Ask Question