Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all,
I have a HTML file, i want to find the string count "Failed" and "Success" and write the output in the csv file with the column1 as current day date, column3 as Success count and column3 as the Failure count
The output should append when ever you run the script
I want the output file as follows
----------------------------------
If run the batch file today the output should beDate SucessCount FailureCount
---- ----------------- --------------
10/29/2009 30 10If run the batch file tomorrow the output should be
Date SucessCount FailureCount
---- ----------------- ----------------
10/30/2009 30 10
10/31/2009 20 20Can you please help me..
Thanks

@echo off & setLocal EnableDELAYedExpansion
for /f "tokens=* delims= " %%a in ('find /c /i "success" ^< my.html') do (
set S=%%a
)
for /f "tokens=* delims= " %%a in ('find /c /i "failure" ^< my.html') do (
set F=%%a
)
>> my.csv echo %date%, !S!, !F!
=====================================
Helping others achieve escape felicityM2

Hi M2 ,
thank for the quick reply , i excuted your script on my HTML File i got the results wrong. i should get 36 Success count and 1 Failed Count ia m gettign 0 count,my HTML File get created by a JAVA Program so it not in proper format as HTML.My HTMLFile looks like this( i tired to attach the file i dont find the attachment option) so i am pasting it here.
---------------------------------<body>
<body>
<!-- DOWNLOAD_LINK --><!--Table1--><div name="hidden" style="background-color: #EFEFEF; width: 500px; "><table style="width: 100%;"><tr style="background-color:white; "><td style="font-weight:bold; font-size:120%; " colspan="4">D1</td></tr><tr><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Project</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Configuration:</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Status:</td></tr><!-- TABLE ENTRY -><tr name="highlightrow"><td></td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY--><!-- TABLE ENTRY --><tr name="highlightrow"><td>M1</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Installer</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>D1</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Engine</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Logic1</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Prod1</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Pub1</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Pub2</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Designer</td><td>DB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>DesignM</td><td>DB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>D2 </td><td>DB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Differ</td><td>DB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Engine</td><td>DB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>LogicDesigner</td><td>DB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>ProdEngine</td><td>DB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>SUN DB </td><td>SUN</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>SUN DB </td><td>SUN</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>SUN Differ</td><td>SUN</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>SUN </td><td>SUN</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>AIX DB </td><td>AIX</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>AIX DB </td><td>AIX</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>AIX Differ</td><td>AIX</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>AIX Engine</td><td>AIX</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>HPUX Differ</td><td>HPUX</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>HPUX Engine</td><td>HPUX</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Linux DB </td><td>Linux</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Linux DB </td><td>Linux</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Linux Differ</td><td>Linux</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Linux Engine</td><td>Linux</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --></table></div><p/><!--Anywhere--><div name="hidden" style="background-color: #EFEFEF; width: 500px; "><table style="width: 100%;"><tr style="background-color:white; "><td style="font-weight:bold; font-size:120%; " colspan="4">Anywhere</td></tr><tr><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Project</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Configuration:</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Status:</td></tr><!-- TABLE ENTRY --><tr name="highlightrow"><td>Anywhere</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Anywhere2</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>DDS.ear</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>DesignServer</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --></table></div><p/><!--Live_Table--><div name="hidden" style="background-color: #EFEFEF; width: 500px; "><table style="width: 100%;"><tr style="background-color:white; "><td style="font-weight:bold; font-size:120%; " colspan="4">Live</td></tr><tr><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Project</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Configuration:</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Status:</td></tr><!-- TABLE ENTRY --><tr name="highlightrow"><td>Live</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Live</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --><!-- TABLE ENTRY --><tr name="highlightrow"><td>Live</td><td>SB</td><td style="background-color:#316745; color:white; width:7%; ">Success</td><td></td></tr><!-- END TABLE ENTRY --></table></div><p/><!--Maint--><div name="hidden" style="background-color: #EFEFEF; width: 500px; "><table style="width: 100%;"><tr style="background-color:white; "><td style="font-weight:bold; font-size:120%; " colspan="4">Maintenance Notes</td></tr><tr><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Project</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Configuration:</td><td style="border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1px; font-weight:bold; ">Status:</td></tr><!-- TABLE ENTRY --><tr name="highlightrow"><td>Maintenance </td><td>SB</td><td style="background-color:#8F2E14; color:white; ">Failed</td><td></td></tr><!-- END TABLE ENTRY --></table></div><p/><!--Unacct_Table--><div name="hidden" style="background-color: #EFEFEF; width: 500px; "><table style="width: 100%;">Can you please help
Thanks.

M2,
I modified his html to make it valid.
I also set up a small test file of my own with 3 records.
I do not get Counts back from your bat file???
I get only the Date and 2 commas?My small file called MyTest.txt has 3 records
Success
Success
FailedThe revised bat file based on yours.
@echo off & setLocal EnableDELAYedExpansionfor /f "tokens=* delims= " %%a in ('find /c /i "Success" ^< C:\Documents and Settings\NewAdmin\My Documents\MyTest.txt') do (
set S=%%a
)
for /f "tokens=* delims= " %%a in ('find /c /i "Failed" ^< C:\Documents and Settings\NewAdmin\My Documents\tmp.html') do (
set F=%%a
)
>> orange.txt echo %date% , !S!, !F!The output:
Mon 11/02/2009 , ,
I also tried the Find statement in cmd window:
C:\Documents and Settings\NewAdmin\My Documents>Find /c /i "Success" MyTest.txt---------- MYTEST.TXT: 2
It seems it is not getting to the files. Any ideas?
I've done some google searching for bat files with a find string and count but can not find the syntax to verify it or to try something different.Thanks.

maybe try using "success"/"fail" as the delimiters? then test for value not null and if not null, increment a counter.
something like:
set delayed expansion...
for /f "tokens=1.. delims=success" %%a in (filename) do (
if %%a NEQ "" set !n!+=
)
i'm new to this, so my code is bad. also, obviously require
two file passes to check the two conditions of succ./fail.
i know this doesn't write the program. maybe point to direction to try.
ps: and i'm sure you're familiar with this, but just to mention: batch script breaks up files into lines based on crlf (car.ret/linefeed) and if the html use obscure variations it might foil the batch parser (for ex: lf-cr, or lf only, or cr only ...) I don't know, i haven't enough experience to say if this matters or not. my feeb attempt based on only one "success"/"fail" per line.

[1] Good idea to make a simple test file. Bad idea to bury it in docu...
[2] The html pasted in by OP is too mangled to use. You can zip it up and email it to me.
[3] Keep in mind that a batch and FIND process BY LINE so we'll get a LINE COUNT. If what's needed is a WORD count, that's another story.
=====================================
Helping others achieve escape felicityM2

M2,
I'm trying to get the bat file you gave to work on a small sample.
My small file called MyTest.txt has 3 records ONLY
Rec# Content
1 Success
2 Success
3 FailedThe modified bat file is
orange1.bat
@echo off & setLocal EnableDELAYedExpansion
for /f "tokens=* delims= " %%a in ('find /c /i "Success" ^< C:\Documents and Settings\NewAdmin\My Documents\MyTest.txt') do (
set S=%%a
)
>> orange.txt echo %date% , !S!The output goes to orange.txt
The result I get is:Tue 11/03/2009 ,
I'm running XP pro sm3. Any advice appreciated.
Orange

I have no way to test it at the moment but maybe this may help:
<untested>
@echo off setlocal enabledelayedexpansion for /f "usebackq delims=" %%a in ("yourfile.htm") do ( set line=%%a if not "!line:^>=!"=="!line!" set line=!line:^>= ! for %%b in (!line!) do >>tempfile.tempfile echo %%b ) for /f %%a in ('type "tempfile.tempfile" ^| find /i "success" ') do set success=%%a for /f %%a in ('type "tempfile.tempfile" ^| find /i "failure" ') do set failure=%%a >> "output.csv" echo !date! !success! !failure! del "tempfile.tempfile" endlocal
The only thing I'm a little iffy on is the special characters. It could be done without a tempfile, but I couldn't see a way to do it without parsing it twice.....

I have actually managed to test this(the script counted 37
"sucess" and 1 "failed", M2's scripts probably work too.
The issue is line length, keep the lines in your html
file under 1000 characters and it should work:The for loop will ignore lines that are too long...
@echo off setlocal enabledelayedexpansion for /f "usebackq eol= delims=" %%a in ("yourfile.htm") do ( set line=%%a set line=!line:"=! set line=!line:^<= ! set line=!line:^>= ! set line=!line:^|= ! for %%b in (!line!) do >>tempfile.tempfile echo %%b ) for /f "tokens=2 delims=:" %%a in ('find /c /i "success" "tempfile.tempfile" ') do set /a success=%%a for /f "tokens=2 delims=:" %%a in ('find /c /i "failed" "tempfile.tempfile" ') do set /a failure=%%a >> "output.csv" echo !date! !success! !failure! del "tempfile.tempfile" endlocal goto :eof

orange,
My first comment in #5 is for you.
=====================================
Helping others achieve escape felicityM2

I got the html in the mail. [Not zipped up. LOL] It's only got 7 lines, 5 of which are about 2000 chars long. So of course it doesn't work.
=====================================
Helping others achieve escape felicityM2

Hi M2,
Sorry for not zipping it up, ya the html is not in proper format , it is getting created by a JAVA program, when i am opeing that html file in notepad++ or notepad it is showing me all code in one line.
Thanks.

M2,
I saw your comment in #5.
My stuff in #7, was trying to get your .bat file to work.
I created a file with only 3 records.
Modified the bat
and get no counts in output.I'm just trying to understand the .bat, especially the For statement with the FIND.
Any help would be appreciated.
I'm not trying to bury this request, I thought it was part of the original since that's where your .bat was given.
Thanks in advance.
orange

Hi all,
Thanks to all of you for putting the effort and time for me, i did a little tweak , and solved the problem i splited the HTML file with perl script (spl.pl) to write each line lessthan 100 chars and created a new HTML file(mod.HTML) and ran the batchscript which you people gave me (fs.bat) ,i put the perl (sp.pl)and batch scritpt(fs.bat) in one batch script (man.bat) and ran the man.bat batch script it ran fine i got the expected results.
Thanks once again to all.
Thanks.

Hi all,
i am trying to calculate the percenstage of the Success Count , i am not getting the output to the excel file., i am using the following script made changes but still i am not getting the output written to the excel file , i want the percentage succes in the other excel file.
@echo off & setLocal EnableDELAYedExpansion
for /f "tokens=* delims= " %%a in ('find /c /i ">Success<" ^< C:\text\man.html') do (
set S=%%a
)
for /f "tokens=* delims= " %%a in ('find /c /i ">Failed<" ^< C:\text\man.html') do (
set F=%%a
)
set /pc=(!S!*100)/(!S!+!F!)
>> my.csv echo %date:~4,14%, !S!, !F!, !pc!
>> per.csv echo !pc!Can you please help where i am doing mistake.
Thanks.

If it's the same file, the lines are too long for a bat script.
=====================================
Helping others achieve escape felicityM2

ThanksM2
the file is MOD.html which i have created using the perl(character per line is lessthan 100)Thank Judago,
That worked.
Thanks.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |