Solved

Batch file

Posted on 2014-10-08
2
328 Views
Last Modified: 2014-10-10
How do I set up a variable that stores the results of this command:

findstr /R /N "^" c:\folder\file.txt | find /C ":"

The command counts the number of lines in a text file.

The goal is to check the number of lines in the text file and if more than 2 lines then continue processing but if less than 2 lines than do nothing.

Thanks for looking! Anything will help.  I'm completely okay if it doesn't work this way but any suggestion or input would be very much appreciated.
0
Comment
Question by:DOMICO Support
2 Comments
 
LVL 37

Accepted Solution

by:
Gerwin Jansen earned 500 total points
ID: 40371723
In a dos/cmd window:
for /f "delims=" %a in ('findstr /R /N "^" c:\temp\usbit32.txt ^| find /C ":"') do @set somevar=%a
echo %somevar%

Open in new window


Then use %somevar% to test for amount of lines.
If you put the above in a batch file, then use %%a instead of %a, like this:

@echo off
for /f "delims=" %%a in ('findstr /R /N "^" "%1" ^| find /C ":"') do @set somevar=%%a
echo "%1" has %somevar% lines

Open in new window

(save the above as lines.cmd)

C:\Temp>dir log.txt
 Volume in drive C has no label.

 Directory of C:\Temp

2014-10-06  07:57             1,390 log.txt
               1 File(s)          1,390 bytes
               0 Dir(s)  259,807,551,488 bytes free

C:\Temp>lines.cmd log.txt
"log.txt" has 51 lines

C:\Temp>
0
 

Author Closing Comment

by:DOMICO Support
ID: 40373508
Gerwin,

You're godsend! Many thanks!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

11 Experts available now in Live!

Get 1:1 Help Now