Solved

Additional lines

Posted on 2014-04-01
4
141 Views
Last Modified: 2014-04-16
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
Comment
Question by:LuckyLucks
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 250 total points
ID: 39970858
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
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39970888
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
 
LVL 11

Assisted Solution

by:paultomasi
paultomasi earned 100 total points
ID: 39974546
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
 
LVL 52

Assisted Solution

by:Bill Prew
Bill Prew earned 150 total points
ID: 39975506
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now