JSI Tip 4732. What command can I add in my batch to count the number of lines in a file?

If you want to add a command in your script that will count the number of lines in a file, use:

for /f %%z in ('find /v /c "" ^

where filename is the path to the file you wish to count.

NOTE: If you wish to display the last n lines of a file, see tip 4574.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.