Warning: count(): Parameter must be an array or an object that implements Countable in /home/devartplus/devartplus.com/wp-content/plugins/maxblogpress-ping-optimizer/maxblogpress-ping-optimizer.php on line 455

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/devartplus/devartplus.com/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Archive

Posts Tagged ‘batch find findstr’

Batch Count Number of Lines in Text File

May 6th, 2011 1 comment

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /home/devartplus/devartplus.com/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

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: