Batch counting number of lines of text file withou

2019-08-09 16:40发布

I got two text files with different formats,let says i already have known there are 4 non-empty lines in the file,shown below (1st is valid, 2nd is invalid).


AAA

BBB

CCC

END

(Blank line)

(Blank line)


AAA

BBB

(Blank line)

CCC

END


Any "for loop" implementations/ways to distinguish 1st file has 4 non-empty lines which can tell it's valid and 2nd file has a extra blank line in the middle which can tell it's invalid.

Because i got a for loop code which can count non-empty line number,applying that code in this 2 files,it gives me line number=4,which i don't want it cause 2nd file is invalid format. my for-loop code

        set count=0
        for /f %%a in (%text_file%) do set /a count+=1
        echo %count%

Any suggestion to identify two files by using lines-counting method?

Or you can tell me how to count the number of lines from starting until the critical string "END",Thanks in advance^.^

1条回答
Juvenile、少年°
2楼-- · 2019-08-09 17:38
for /f "tokens=1 delims=:" %%i in ('findstr /n "^END$" %text_file%') do set endline=%%i
echo %endline%

this finds the linenumber of the (last) line, that is equal to <StartOfLine>END<EndOfLine>

查看更多
登录 后发表回答