Archive

Posts Tagged ‘batch find findstr’

Batch Count Number of Lines in Text File

May 6th, 2011 1 comment

Recently I came across the need to count the number of lines in a text file, so I decided to explore Command Shell options.

My first thought was to use Find command, but I was not able to find a new line character, so I decided to count lines, which are not containing the certain string:

find /c /n /v "***///" CreateLogTable.sql

This approach works not bad, but it opens a breach in cases when the string, which is used as a search token, can be actually a part of the file.

After some more research I found out that there is another batch command, called FindStr. This command supports regular expressions and allows us to count the number of lines without any exceptions:

findstr /R /N "^" CreateLogTable.sql | find /c ":"
Categories: General Tags: