• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Additional lines

Hi EEE:


 How do I count the number of lines in a file? I guess when one of my fields in the line is big I am worried if the line is breaking into two, creating additional rows. How can I verify this in the batch? Using a text editor is a bit tricky because they may be counting the lines by different endpoints. I imported the csv file into access and the total rows looked correct whereas in Notepad ++ there were additional lines.

Please help solve thi mystery.
0
LuckyLucks
Asked:
LuckyLucks
  • 2
3 Solutions
 
becraigCommented:
Batch File

@Echo OFF
for /f %%A in ('Find /V /C "" ^< c:\file.txt') do set Count=%%A
echo The file has %Count% lines.
0
 
Bill PrewCommented:
Even easier than that, and this will count blank lines where FOR won't, at a command prompt do:

find /c /v "" filename.txt

~bp
0
 
paultomasiCommented:
I prefer the following:

for /f "tokens=3" %%a in ('find /c /v "" filename.csv') do echo %%a Line(s)

Open in new window

0
 
Bill PrewCommented:
Hmmm, why would one want to type more than needed to get the line count Paul?

But if you feel there is a need for that, then the proper way to handle that would be:

for /f %%a in ('find /c /v "" ^<"filename.csv"') do echo %%a Line(s)

Open in new window

This will handle the case correctly where a filename contains spaces, which your approach would have a problem with.

~bp
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now