vbscript - Extract text string from file -
i writing utility collect system information devices on network xml document, , 1 of values software version number. unfortunately version number stored in single text file on each machine (c:\master.txt) more fun part is, each text file formatted differently depending on image used.
one say
product number: 11dsst2 brandonii,stns6.0.2.200
the next
ver: 22335ts box2 s6.1.3.011,stn
and on.
what did, create vbs looks number pattern matches version pattern,
[a-z]#.#.#.###
this works, want output pattern, not entire line. here code. suggestions?
const forreading = 1 set objregex = createobject("vbscript.regexp") objregex.pattern = "[a-z]{1}[0-9]{1}.[0-9]{1}.[0-9]{1}.[0-9]{3}" objregex.global = true objregex.ignorecase = true set objfso = createobject("scripting.filesystemobject") set objfile = objfso.opentextfile("c:\master.txt", forreading) until objfile.atendofstream strsearchstring = objfile.readline set colmatches = objregex.execute(strsearchstring) if colmatches.count > 0 addmatch end if loop objfile.close sub addmatch 'creates text file part number const forappending = 8 set objfso = createobject("scripting.filesystemobject") set objfile1 = objfso.opentextfile("c:\test.txt", forappending, true) objfile1.writeline strsearchstring objfile1.close end sub
you're storing entire line read file (that have in strsearchstring
) instead of matched text. use instead (untested!):
if colmatches.count > 0 addmatch(colmatches(0)) ' grab matched text , pass addmatch end if sub addmatch(strmatchedtext) ' change accept parameter of text write out ' other code objfile1.writeline strmatchedtext objfile1.close end sub
Comments
Post a Comment