Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Additional lines

Posted on 2014-04-01
4
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 1000 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 58

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 400 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 58

Assisted Solution

by:Bill Prew
Bill Prew earned 600 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 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