Home > General > Batch Count Number of Lines in Text File

Batch Count Number of Lines in Text File

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:
  1. March 6th, 2016 at 13:51 | #1

    Up until now, all our updates have been thogurh nHibernate. We did however spike out sharing transaction contexts between them, by supplying the transaction context as we create the sessions for each. Generally, though, for the really complex queries where iBatis shines, we’re just reading stuff, not updating it.

  1. No trackbacks yet.