批量计算文本文件的行数,不留空白 [英] Batch counting number of lines of text file without blank

查看:89
本文介绍了批量计算文本文件的行数,不留空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个格式不同的文本文件,可以说我已经知道文件中有4个非空行,如下所示(第1个有效,第2个无效)。

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

(空白行)

(空行)

AAA

BBB

(空白行)

CCC

END

任何 for循环实现/区分第一个文件的方式都有4个非空行,可以分辨出它是有效的还是第二个文件

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.

因为中间有一个多余的空行,可以表明它是无效的。因为我有一个for循环代码,可以计算非空行号,因此将该代码应用于此2个文件,它给我行号= 4,我不想要它,因为第二个文件格式无效。
我的for循环代码

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?

或者您可以告诉我如何计算从开始到关键字符串 END之间的行数,谢谢。^

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

推荐答案

for /f "tokens=1 delims=:" %%i in ('findstr /n "^END$" %text_file%') do set endline=%%i
echo %endline%

这会找到(最后)行的行号,该行号等于< StartOfLine> END< EndOfLine>

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

这篇关于批量计算文本文件的行数,不留空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆