I'm trying to do pattern matching on a pattern containing a substring which varies (which I'd like to save). For example
Test pattern example1 for showing stuff.
Test pattern the second example for showing stuff.
So string would be like.
Test pattern %variable for showing stuff.
Need to find that pattern (It will be in a text file) then save whatever is between "pattern" and "for showing.."
How would I do this?
Pattern Matching & Variables
Moderators: JRL, Dorian (MJT support)
No idea if I've got it,
input.txt
bbbbbbbb
bbbbbbbb
aaavarccc
bbbbbbbb
aaavarccc
bbbbbbbb
bbbbbbbb
bbbbbbbb
so you want to find all aaa lines in the file input.txt to get the variable part out of it?
cmd = WINNT,W2K,XP
command= WIN9x,ME
input.txt
bbbbbbbb
bbbbbbbb
aaavarccc
bbbbbbbb
aaavarccc
bbbbbbbb
bbbbbbbb
bbbbbbbb
so you want to find all aaa lines in the file input.txt to get the variable part out of it?
Code: Select all
Let>ln=0
Let>1pat=aaa
Let>2pat=ccc
Run Program>cmd /c find "%1pat%" c:\input.txt > C:\output.txt
Label>scanfile
Add>ln,1
ReadLn>C:\output.txt,ln,line
If>line=##EOF##,End
Position>2pat,line,1,varpos
Sub>varpos,4
MidStr>line,4,%varpos%,var
Message>variable: %var%%CRLF%line: %line%
Goto>scanfile
Label>End
command= WIN9x,ME
Almost..
Your example is much better than mine hehe. So
aaaaaaaaa
bcdVARcbd
aaaaaaaaa
aaaaaaaaa
ok the catch is i dont know what VAR is, like I said it varies. I only know that it will be contained inside the pattern "bcd" followed by "cbd" as demonstrated above. So i want to find the pattern bcd and save whatever is between bcd and cbd to a variable.
Also there will only be one instance of bcdVARcbd, the one I want to find. I just dont know where it will be or what var will be.
aaaaaaaaa
bcdVARcbd
aaaaaaaaa
aaaaaaaaa
ok the catch is i dont know what VAR is, like I said it varies. I only know that it will be contained inside the pattern "bcd" followed by "cbd" as demonstrated above. So i want to find the pattern bcd and save whatever is between bcd and cbd to a variable.
Also there will only be one instance of bcdVARcbd, the one I want to find. I just dont know where it will be or what var will be.
That code helped a lot, thanks. Here is what i ended up with:
//ln determined elsewhere
Let>1pat=aaa
Let>2pat=ccc
Run Program>cmd /c find "%1pat%" C:\input.txt > C:\output.txt
ReadLn>C:\output.txt,ln,line
Position>2pat,line,0,varpos1
Position>aaa,line,0,varpos2
Let>varpos2=varpos2+4
Let>varpos1=varpos1-%varpos2%
MidStr>line,%varpos2%,%varpos1%,Var
Message>%Var%
//ln determined elsewhere
Let>1pat=aaa
Let>2pat=ccc
Run Program>cmd /c find "%1pat%" C:\input.txt > C:\output.txt
ReadLn>C:\output.txt,ln,line
Position>2pat,line,0,varpos1
Position>aaa,line,0,varpos2
Let>varpos2=varpos2+4
Let>varpos1=varpos1-%varpos2%
MidStr>line,%varpos2%,%varpos1%,Var
Message>%Var%