comprehensively edit an html from batch file

May 17, 2009 at 09:26:04
Specs: Windows XP
Hi, I'm seaching everywhere but could'n find ANY way to complete this task.

I have an HTML file that has a specific string, and I want to delete anything before and including that string, then do the same to another string, and after that another string. basically, I have

JUNK_STRING1_usefuldata_STRING2_JUNK

and I want to generate a file with only the "usefuldata" part. Also note that there ARE CR+LFs in place, so it's not a per-line editing task.

The only scripting I know is batch and quick'n'dirty VBScript, so please don't suggest me to do C++ coding or something... And freeware solutions are very welcome.

thanks for any info on this, would be very appreciated.
Camilo


See More: comprehensively edit an html from batch file

Report •


#1
May 17, 2009 at 10:12:44
How about BK Replacem (http://www.ecobyte.com/replacetext/)

-Ryan Adams
Free Computer Tips and more:http://RyanTAdams.com

Paid Tech Support: Black Diamond


Report •

#2
May 17, 2009 at 10:23:17
Hi Ryan!

Well, I think i didn't express mysef well.
It's not that I don't like GUIs, but I need this to be done from the commandline. the reason for this is that it's part of a bigger process that should be run with no more user interaction than clicking on a bat file.

so, my ideal solution would be a CLI util that I can call from a bat script to delete anything before/after a certain string.

thanks for the answer btw, very fast =)


Report •

#3
May 17, 2009 at 12:14:00
Using that program, you can generate a saved set of replace options into a file. The program can then be run from the command line with the options file passed to it.

This would of course require the program to be present on the computer, but I would image you could package the program EXE, the options file, and a batch file to run it all together rather easily.

If that isn't possible, I'm pretty sure it can be accomplished with VBScript. Will it always be interacting with the same files(s)? Will it always be looking to remove the same string(s)?

-Ryan Adams
Free Computer Tips and more:http://RyanTAdams.com

Paid Tech Support: Black Diamond


Report •

Related Solutions

#4
May 17, 2009 at 18:06:32
well if you know vbscript, and you know what "usefuldata" is,
1) get the starting index using Instr
2) once you get the index , did substring from 0 to that index using Mid() to get rid of the front portion
3) then you will have left this : usefuldata_STRING2_JUNK
4) get the index of the first "_" using Instr() again
5) do a Mid() from that index till the end. then you are left with your output

or if you know where exactly "ussfuldata" is, you can do a split on the string with delimiter "_", then get the 3rd element.


Report •

#5
May 20, 2009 at 00:54:54
hi, thanks to both of you!
but I'm here to inform that my project will be a little more complex than I expected so I'll have to make sure I can code harder parts first, so I plan to come back here to report if those two options worked.
I'm confident Ryan's solution will work nicely, anyway I just got an idea to do it from bat files;
use FINDSTR to enumerate lines, use it again to look where _STRING1_ is, delete all lines before it using some simple math in SET /A and lots of unnecessary code (I hate some things about bat files, I HAVE to learn something better!) to discard those lines, then do the same with the lines after _STRING2_ and cleanse the rest from heading line numbers. then cleanse both strings, and voila, magic is done.

I don't know if that was understandable, but It's in fact a miracle if it works. anyway, is there a way to use FOR to process lines? That command is so obscure to me somehow.
And doing FOR /? makes me dizzy :(
something like
FOR %%A IN (line1, line2 ... lineX) DO COMMAND line#
is it just a dream? '--'


Report •


Ask Question