Page 1 of 1

Help for grep and array

Posted: 20 Mar 2018, 19:50
by maitresin
Hello,

I want to do a grep and paste result into a .txt with both result from "g" and "g2" and so on. Please see below code and let me know what to enter in the "for i, v in g" section

Thanks!

Code: Select all

g:=grep(fileread2, "sU)id=""(.*)""")
g2:=grep(fileread2, "sU)No=""(.*)""")

countx := g.MaxIndex()
countx2 := g2.MaxIndex()

for i, v in g    ;Here I want to fileappend the first result found of "g" and "g2" and paste it into the "OrderID.txt". I know it is not good but it show what I want to do.
{
result1 := v.1
for i, w in g2
{
    result2 := w.1
}
fileappend, %result1% %result2% `n, OrderID.txt
}


grep(haystack, needle)
{
    a:=[], match := "", pos := 1
    while pos:=RegExMatch(haystack, needle, match, pos+StrLen(match))
        a[A_Index]:= {"match": match, 1: match1}
    Return a
}


Re: Help fro grep and array

Posted: 20 Mar 2018, 22:43
by maitresin
The following code work. However, I get every result in double! :( What is wrong?

Code: Select all

for i, v in g
{
result1 := v.1
gosub, secondgrep
fileappend, %result1% %result2% `n, OrderID.txt

}

secondgrep:
for i, w in g2
{
    result2 := w.1
}
continue
return

Re: Help fro grep and array

Posted: 21 Mar 2018, 16:57
by maitresin
Anyone able to help?

Thanks!

Re: Help fro grep and array

Posted: 21 Mar 2018, 17:13
by gregster
Perhaps you should provide the input and the expected result. That could help others to help you.

Re: Help fro grep and array

Posted: 21 Mar 2018, 18:31
by maitresin
Exemple of Value in files: Id="11316832" No="90001267"

Expected Output in OrderId.txt : 11316832 90001267

Current Output in OrderId.txt: 11316832 90001267 ; it double the output :\
11316832 90001267

Re: Help fro grep and array  Topic is solved

Posted: 21 Mar 2018, 20:37
by maitresin
nvm found the solution