Solved

Batch file

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Introduction to Processes
Starting up a Project

695 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