The following code snippet does what you want, using a temporary file:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_CSV_FILE=%~1" & rem // (specify CSV file here; `%~1` is first argument)
set "_NUM_FRST=0" & rem // (specify number of lines to remove from beginning)
set "_NUM_LAST=11" & rem // (specify number of lines to remove from end)
rem // Count number of available lines in file:
for /F %%C in ('^< "%_CSV_FILE%" find /C /V ""') do set /A "COUNT=%%C"
set /A "COUNT-=_NUM_LAST"
rem /* Process file, regarding and maintaining empty lines;
rem lines must be shorter than about 8190 bytes: */
> "%_CSV_FILE%.tmp" (
set /A "INDEX=0"
for /F "delims=" %%L in ('findstr /N "^" "%_CSV_FILE%"') do (
set /A "INDEX+=1"
set "LINE=%%L"
setlocal EnableDelayedExpansion
if !INDEX! GTR %_NUM_FRST% if !INDEX! LEQ %COUNT% echo(!LINE:*:=!
endlocal
)
)
rem // Overwriting original file:
> nul move /Y "%_CSV_FILE%.tmp" "%_CSV_FILE%"
endlocal
exit /B
The following approach does not use a temporary file:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_CSV_FILE=%~1" & rem // (specify CSV file here; `%~1` is first argument)
set "_NUM_FRST=0" & rem // (specify number of lines to remove from beginning)
set "_NUM_LAST=11" & rem // (specify number of lines to remove from end)
rem // Count number of available lines in file:
for /F %%C in ('^< "%_CSV_FILE%" find /C /V ""') do set /A "COUNT=%%C"
set /A "COUNT-=_NUM_LAST"
rem /* Process file, regarding and maintaining empty lines;
rem lines must be shorter than about 8190 bytes: */
set /A "INDEX=0"
for /F "delims=" %%L in ('findstr /N "^" "%_CSV_FILE%" ^& ^> "%_CSV_FILE%" rem/') do (
set /A "INDEX+=1"
set "LINE=%%L"
setlocal EnableDelayedExpansion
if !INDEX! GTR %_NUM_FRST% if !INDEX! LEQ %COUNT% >> "!_CSV_FILE!" echo(!LINE:*:=!
endlocal
)
endlocal
exit /B