At0mic Posted August 31, 2006 Posted August 31, 2006 I want to search for a string in an html file. The line I need contains a number which constantly changes. There isn't anything else on this line which is unique. Therefore, I would have to search for the line above.Here's is a small part of the html document:Total</TD><TD COLSPAN="3" HEADERS="Total">184394</TD></TR></TABLE>The number "184394" is the information I need but its a different number each time the webpage is saved (I'm using Downloader.exe to save it)The first problem, is if I search for "TD COLSPAN=" it finds 3 instances in the file. I cant specify a longer string becasue the quotation marks mess it up but maybe there is a way around this?Here's the code I have so far:downloader.exe -download http://192.168.0.94/m_s_cnt.htm lobby.htmFIND "TD COLSPAN" "lobby.htm" >>lobby.textHow can I grab the next line down from the search string "TD COLSPAN="? Ive checked all the switches for both the Find and Findstr commands, but I cant see anything useful. I dont know enough about scripting to be able to work it out.Here's the full HTML file if anyones interested (its the page counter from a network printer)lobby.htm
jftuga Posted September 1, 2006 Posted September 1, 2006 findstr /b "[0-9].*</TD>" lobby.txt/b start at the beginning of the line.[0-9].* looks for a digit which can be repeated until </TD> is reached-John
At0mic Posted September 2, 2006 Author Posted September 2, 2006 Your solution work's thank you very much. However, a total of 7 lines match the string:97727</TD>1806</TD>32860</TD>86981</TD>492</TD>8028</TD>184708</TD>I modified the code to add a line number and then I added another line to use the line number as a string:findstr /b /n "[0-9].*</TD>" Lobby.htm > temp.txtecho Page count for the WHSE Lobby printer > total.txtfindstr "140" temp.txt >> total.txtdel temp.txtThis resulted in the following:Page count for the WHSE Lobby printer 140:184708</TD>I wasn't very happy with having "140:" and "</TD>" so I did a search using google and found Munge.exe from the NT4 Resource Kit which can replace strings. I tried it out and it worked perfectly. Here's the new code:findstr /b /n "[0-9].*</TD>" Lobby.htm > temp.txtecho Page count for the WHSE Lobby printer > total.txtfindstr "140" temp.txt >> total.txtMUNGE munge.txt -l -t total.txtdel temp.txtmunge.txt contains the following:"140:" """</TD>" ""When I run the script, I get the following which I'm very happy with:Page count for the WHSE Lobby printer 184708I've got another 6 html files to retrive some numbers from so I'll continue with it on Monday. Some of them will require some numbers to be added up so I'll try a command line calculator.
uid0 Posted September 4, 2006 Posted September 4, 2006 You can use SET for a bit of command line mathsCareful not to over-file that bath
jaclaz Posted September 4, 2006 Posted September 4, 2006 Some of them will require some numbers to be added up so I'll try a command line calculator....or the SET /A command ....http://www.robvanderwoude.com/ntset.htmljaclaz
At0mic Posted September 9, 2006 Author Posted September 9, 2006 Thanks for the help guys, I've almost finnished.Just one more thing though, how can I SET the output of the FINDSTR command to a variable instead of to a txt file?I've tried the following but it sets the actual command as the variable instead:SET total="findstr "[0-9]" total.txt"
jftuga Posted September 10, 2006 Posted September 10, 2006 findstr "[0-9]" total.txt > c:\temp\results.txtset /p total=<c:\temp\results.txt@echo %total%-John
At0mic Posted September 13, 2006 Author Posted September 13, 2006 Thanks everyone for your help, especially to jftuga " Bath file "... I lol'd Did I miss something?
Tarun Posted September 13, 2006 Posted September 13, 2006 Thanks everyone for your help, especially to jftuga " Bath file "... I lol'd Did I miss something? The topic title. Just don't drop the soap.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now