Pattern Matching & Variables

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Klion

Pattern Matching & Variables

Post by Klion » Fri May 23, 2003 10:48 am

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?

Klion

Oh also..

Post by Klion » Fri May 23, 2003 10:52 am

On a slightly different note any idea why wait> commands would generate windows errors in windows 98SE? The same script works fine in windows XP but all the wait> commands generate errors under 98.

Lumumba

Post by Lumumba » Fri May 23, 2003 1:34 pm

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?

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
cmd = WINNT,W2K,XP
command= WIN9x,ME

Klion

Almost..

Post by Klion » Fri May 23, 2003 2:23 pm

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.

Klion

oops

Post by Klion » Fri May 23, 2003 2:26 pm

nevermind its 7:30 in the morning I shouldnt be reading code. Think thats it thanks :P

Klion

Post by Klion » Fri May 23, 2003 4:37 pm

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%

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts