Computing.Net > Forums > Programming > Batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch file

Reply to Message Icon

Name: Aaradhana
Date: February 26, 2009 at 02:40:40 Pacific
OS: Windows XP
CPU/Ram: 1GB
Subcategory: Batch
Comment:

Hi guyz,

I need to extract a number from a html file which looks roughly as below:

<th>Total</th>
<th>Pass</th>
<th>Fail</th>

<tr>
<td align="center" >61</td>
<td align="center" style=" color: green" >47</td>
<td align="center" style="color: red" >14</td>

</tr>
</table>

Here I need to extract the numbers 61, 47 n 14 using a batch file.

The numbers extracted should be stored in variables so that i can use them in rest of
code.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Sandy (by sandeepankumar)
Date: February 26, 2009 at 04:25:29 Pacific
Reply:

Hi Aradhana,

I don't know how to do it using a batch file but you can do it using the JavaScript.

-Sandy

Sandy!


0

Response Number 2
Name: Aaradhana
Date: February 26, 2009 at 22:37:50 Pacific
Reply:

Thanks for ur reply.
But, actually i have written the remaining part of code using batch file n just got stuckup with this single problem.


0

Response Number 3
Name: Judago
Date: February 27, 2009 at 15:24:09 Pacific
Reply:

Based on what you posted this may work:

SETLOCAL ENABLEDELAYEDEXPANSION
set n=
for /f "tokens=2 delims=^<^>" %%a in ('find /i "td align" "file name"') do (
set /a n+=1
set num!n!=%%a
)

That is assuming that tags aren't doubled up on lines and you only want "td aline" lines....


0

Response Number 4
Name: Aaradhana
Date: March 3, 2009 at 03:34:30 Pacific
Reply:

hi Judago,

Thanks for ur reply :)

The for loop you mentioned is fine

using "for /f "tokens=4 delims=^<^>" %%a in ('find /i "td align" "file name"') do ("
i'm able to grep the first value i.e., 61 during one interation in the for loop

using "for /f "tokens=3 delims=^<^>" %%a in ('find /i "td align" "file name"') do ("
i'm able to grep the second & third values i.e., 47 & 14 during second and third interations in the for loop

but how can i access the values
i mean is it like %num!1!%

sry it might be a silly doubt but i'm very new to batch files..

could you please help me with this??

Thanks
Aaradhana


0

Response Number 5
Name: Judago
Date: March 3, 2009 at 13:05:22 Pacific
Reply:

Firstly in batch files no variables can start with numbers so !1! is invalid, this is because of a conflict(%2var%) of parameters %1 %2 ...

You can just use !var1! or %var1% but if the number your using is inside a variable you almost have it use !num%var%! instead of %num!var!%.

If you need the number to be a dynamic variable(which it won't be in the example above) there is a trick involving a for loop that can be used.

for %%a in ("!num!") do command involving !num%%~a!

The quotes aren't strictly necessary but often are as the conventional for loop has multiple, un-settable delimiters. Mainly (; = , ) but I think there are also a few more.

if you have multiple variables that don't contain any spaces the trick above can be built upon using for /f.

for /f "tokens=1-3 delims= " %%a in (!var1! !var2! !var3!) do echo %%a %%b %%c....

Here is an example of non dynamic nested variables.

set num=1
set var1=test
call echo %%var%num%%%

Remove the outermost set of %'s to use on the command line.

[edit]

Correction:

!1! can be a valid variable but %1%, whilst within a script, cannot. The variable %1% can also be valid from the command line. Variables that start with numbers can only be expanded as dynamic with delayed expansion due to the conflict with parameters mentioned above.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Google Chrome inserts har... in shell script



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: Batch file

Batch file to count a specific character in a www.computing.net/answers/programming/batch-file-to-count-a-specific-character-in-a/19751.html

FTP batch file www.computing.net/answers/programming/ftp-batch-file/9027.html

batch file www.computing.net/answers/programming/batch-file/13936.html