Solved

Batch file

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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…

776 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