Solved

Additional lines

Posted on 2014-04-01
4
140 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 28

Accepted Solution

by:
becraig earned 250 total points
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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 51

Assisted Solution

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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 …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

8 Experts available now in Live!

Get 1:1 Help Now