Computing.Net > Forums > Programming > Store the result in a variable

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Store the result in a variable

Reply to Message Icon

Name: Noor2000
Date: August 29, 2004 at 08:39:55 Pacific
OS: Windows2000
CPU/Ram: 256
Comment:

Hi all,
I'm a beginner in batch files. I'm trying to read how many lines are in a file(lets say test.txt), store this number in a variable and depending on the value of this variable I will run Script1 or Script2:
I put
Set Lines=find /C < test.txt
If Lines =< 12 CALL Sript1
If Lines >12 CALL Script2

I know that even the first line doesn't work, any help, I have also another issue since my OS is W2k do I have to erase this temporary variables at the end or to be aware of somthing when I'm running batch files on W2K.

Thank you



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: August 30, 2004 at 01:06:28 Pacific
Reply:

The script that fits your need is the following
(Type CFind File_Name to run, assumed CFind.bat is the script)

@Echo Off

For /F "tokens=2 delims=:" %%A in ('Find /C /V ^"$@?^" %1') Do Set Lines=%%A

If %Lines% leq 12 Call Script1
If %Lines% gtr 12 Call Script2

Set Lines=

The For /F statement fits one line without CR/LF.

The last command erases the variable and it is a good practice to clean up before leaving. Anyway the script language for Win NT/2K/XP is a superset of the DOS batch one, more powerfull, but more complex too.

I guess you need deeper exposure to the issue.


0

Response Number 2
Name: Noor2000
Date: September 1, 2004 at 11:49:11 Pacific
Reply:

Hi Ivo,
The batch doesn't work like It should, for this file:

Volume Name State Last Update Automated
Date/Time LibName
-------------------------
000017 Mountable 01-09-2004 14:03:29 LIBRARY1
000027 Mountable 01-09-2004 13:29:08 LIBRARY1

Lines is equal=6, Since me I want just to look for the lines begining with 00 I do: find /c "00" so lines has the value of 0 which is not true

Any Idea
Thanks


0

Response Number 3
Name: IVO
Date: September 2, 2004 at 01:29:00 Pacific
Reply:

Have you replaced ('Find /C /V ^"$@?^" %1') with ('Find /C ^"00^" %1')? Otherwise you get 0 in the Lines variable as /V forces to count lines NOT holding the string and the ^ (caret) is required inside a compound (For /F) command.

Following my tip your script should work.


0

Response Number 4
Name: Noor2000
Date: September 2, 2004 at 12:03:34 Pacific
Reply:

Thank you a lot IVO, you are really amazing
Thank you a lot
Noor


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Store the result in a variable

Grand Total of variables in a loop www.computing.net/answers/programming/grand-total-of-variables-in-a-loop/15996.html

Using A Dialog In Shell www.computing.net/answers/programming/using-a-dialog-in-shell/4652.html

how store ping result www.computing.net/answers/programming/how-store-ping-result/1321.html