Solved

Batch file

Posted on 2014-10-08
2
349 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 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.

828 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