Hi Vbgurus,
I’m trying to put together a script about which I’m not getting things right. Hope you may help me in getting it done.
I’m looking for a vbscript that will search for a specific string, if found, check for first occurence of another string and read the line that follow it. For e.g. my file would be like,
….
…..
……
STAGE
…..
…..
…..
….
FROM
<string to be extracted>
…
…
….
As in the above example, the script should search for the word “STAGE” first, if found check for the first occurence of word – “FROM” and read the line that follows – FROM.
NOTE – My file would have many such occurences and hence, I should search like above, and keep writing the STAGE, FROM & the immediate line to an xl file.
Thanks in advance for any help that you may offer.
There are questions, applying to both triggers (STAGE, FROM): are these always in caps? Do they always begin a line (ie: always preceded by either null or crlf)? Is there a terminating character (space, colon, whatever) to the string, or alternatively, is there any chance that “stage” or “from” could occur in the text stream other than your designated triggers? That said, here’s my initial stab at it:
‘========== begin vbscript
set fso=createobject(“scripting.filesystemobject”)
z=vbcrlf&fso.opentextfile;(“vbst”,1).readall
x=split(z,vbcrlf&”STAGE”,-1,vbtextcompare)
for i=0 to ubound(x)
p=instr(1,x(i),”from”,vbtextcompare)
if p>0 then
y=split(mid(x(i),p+4),vbcrlf)
targ=y(0)
if targ=”” then targ=y(1)
wscript.echo targ
end if
next
‘======= end vbscript
edited to reflect updated requirements 11/16 pm brief test