Solved Creating Batch file for Last 10 lines in a folder

May 14, 2012 at 03:27:30
Specs: WinXP
Hi,

I manage to find a batch file for getting the last 10 lines for a file, but how to I get the last 10 lines for all the csv files in the folder?

Thanks.
Jeremy

@echo off > newfile & setLocal enableDELAYedexpansion

set N=
for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
)
set /a X=!N!-10
set N=

for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
if !N! gtr !X! echo %%a >> newfile
)


See More: Creating Batch file for Last 10 lines in a folder

Report •


#1
May 14, 2012 at 17:23:32
✔ Best Answer
You CALL a subroutine for each csv.


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
May 14, 2012 at 23:18:29
Thanks!

I got it working

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%A in ('dir /b *.csv') do (
set NAME=%%~nA
call :sub1 %%A
)
goto :eof

:sub1

set N=
for /f "tokens=* delims= " %%L in (%*) do (
set /a N+=1
)
set /a X=!N!-10
set N=

for /f "tokens=* delims= " %%L in (%*) do (
set /a N+=1
if !N! gtr !X! echo %%L >> !NAME!Done.csv
)


Report •

Related Solutions


Ask Question