|using batch to parse file, especially files with XML structure is just asking for trouble. The ideal method to parse HTML/XML files is to use a tool/programming language with libraries that makes manipulating HTML/XML files easier for the human being. Such languages may be Perl, Python etc. If that option is not available, at least use a tool that is meant for text/string manipulation. eg Perl, Python, awk, even vbscript makes string manipulation easier.|
since you are a beginner, i suggest you take the time to learn something else. But in the meantime, here's a vbscript
that shows you how to do it the easier way..
strFile = "c:\test\file"
Set objFile = objFS.OpenTextFile(strFile)
q = """" 'double quote
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
s = Split(strLine,q&" ")
For i=LBound(s) To UBound(s)
If InStr(s(i),"Field4")> 0 Then
WScript.Echo "I found field 4 ", s(i)
ElseIf InStr(s(i),"Field3") > 0 Then
WScript.Echo "I found field 3", s(i)
C:\test>cscript /nologo test.vbs
I found field 3 Field3="My description for this
I found field 4 Field4="0
I found field 3 Field3="damn difficult
I found field 4 Field4="1
for you other questions,
1) check for blanks at 8th character, you can use Mid() function together with if/else
2) to check numeric, there is the IsNumeric() function.
GNU win32 packages | Gawk