Solved

Batch file

Posted on 2014-10-08
2
355 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
[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 Comments
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

734 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