Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

Hi Aradhana,
I don't know how to do it using a batch file but you can do it using the JavaScript.
-Sandy
Sandy!

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.

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....

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 loopusing "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 loopbut 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

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.

![]() |
Google Chrome inserts har...
|
in shell script
|

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