|
Post by Johnc on Aug 8, 2019 14:02:40 GMT
Hi Steve, good day! Is there a way to do table lookup in MMM? Something like an associative array in awk?
I have a text file like this:
John red honda Mary blue toyota Jimmy black gm ...
if I give MMM "John", it should return "honda" etc...
Tks!
|
|
|
Post by Johnc on Aug 9, 2019 18:51:52 GMT
Found a way and it worked on windows 7 x64!
Note %STRING% contains the search key e.g. John or Mary or ... The returned value from the lookup table "people_car_list.txt" is stored in the clipboard.
The | pipe operator was escaped by \ (i.e. \|) Good job Steve! Now I don't need to write "external" awk scripts as they can be embedded into MMM!
192 | RUN ACTION | | | | RUN VIA CMD /C | title=runscript & awk 'index($1,"%STRING%"){print $3; exit}' E:\File_John\F_variable\people_car_list.txt \| CLIP 193 | RUN ACTION | | | | WAIT SECONDS | 1 194 | IF | WINDOW TITLE | runscript | NOT EXIST | CONTINUE
|
|
|
Post by Steve on Aug 10, 2019 2:39:31 GMT
Hi John, MMM natively can't do a lot with strings. I've been meaning to add a lot more in for strings. The only way to get this done is to parse the output of MMM to an external tool like you've done with the windows shell. Also, your MMM syntax with the gaps between your actions has been depreciated out of the code since version 6.8 back last October. There is still backward functionality but its best to try and avoid them if you can. It might cause some trouble later on. So this:
192 | RUN ACTION | | | | RUN VIA CMD /C | title=runscript & awk 'index($1,"%STRING%"){print $3; exit}' E:\File_John\F_variable\people_car_list.txt \| CLIP 193 | RUN ACTION | | | | WAIT SECONDS | 1 194 | IF | WINDOW TITLE | runscript | NOT EXIST | CONTINUE Turns to this:
192 | RUN ACTION | RUN VIA CMD /C | title=runscript & awk 'index($1,"%STRING%"){print $3; exit}' E:\File_John\F_variable\people_car_list.txt \| CLIP 193 | RUN ACTION | WAIT SECONDS | 1 194 | IF | WINDOW TITLE | runscript | NOT EXIST | CONTINUE
|
|
|
Post by Johnc on Aug 10, 2019 13:08:13 GMT
oic, let me get rid of all the gaps then. BTW, I am totally happy now with the way I can pipe things to the windows shell and then get the results back from the clipboard. Somehow it was not possible before because the | pipe operator couldn't be escaped. This way, I can keep all awk/sed codes inside a MMM macro rather than having to scatter them into many small .bat files. Thanks so much Steve for making this happen!
|
|