1.

Solve : skip last line using a for loop?

Answer»

using sqlcmd option in sql server, i generated a text file

in a batch script am taking that text file as input and processing a for loop there.

but how can i skip the LAST LINE of the text file without running in the for loop

i can USE skip=2 to skip the two lines.

in the ending i have query result information LIKE '40 row(s) selected '

I want to skip that without processing by for loop

Any help or idea is enough.. please helptry this in the loop
Code: [Select]for /f "delims=" %%a in ( ' find /v "(s)" yourfile.txt ' ) do ???????This filters out the unwanted lines from your fileAnother way is to use two FOR loops... the first one just counts the lines and thus you you know the number of the last line, the second one echoes all the lines except the last one

Code: [Select]echo off
setlocal enabledelayedexpansion
REM Loop (1) count lines
set line=0
for /f "delims=" %%L in ( ' TYPE "myfile.txt" ' ) do set /a line+=1
REM Subtract 1 from total
set /a maxline=%line%-1
REM Loop (2) echo every line in file except the last
set line=0
for /f "delims=" %%L in ( ' type "myfile.txt" ' ) do (
if !line! lss %maxline% echo %%L
set /a line+=1
)



Discussion

No Comment Found