Match a file value with another file value Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

Match a file value with another file value

19 Dec 2022, 20:25

I have a master file that return the equivalent of a string. MasterListing.txt
Exemple of that file:
ABC = B.2
DEF = B.5
HIJ = B.12

I also have multiple file:
File-1.txt
File-2.txt
File-3.txt
...
and so on but can be 1, 2, 10 or more files with same patern. There is only 1 value per file.

In those file there are value like:
ABC or DEF or HIJ and so on... many different codes

How could I create a new file with the same file patern as File-1.txt and so on but with the equivalent value from the MasterListing.txt? Only the equivalent value and not the ABC =

Thanks!
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Match a file value with another file value

19 Dec 2022, 20:28

I suggest that you attach one example of each of the three files, or provide the three specific examples.
Last edited by mikeyww on 19 Dec 2022, 20:45, edited 1 time in total.
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

Re: Match a file value with another file value

19 Dec 2022, 20:44

The Master List
MasterListing.txt
(32 Bytes) Downloaded 31 times
File to match with the Master List
File-1.txt
(3 Bytes) Downloaded 25 times
Expected result
Result-1.txt
(3 Bytes) Downloaded 21 times
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Match a file value with another file value

19 Dec 2022, 20:45

Code: Select all

dir         = %A_ScriptDir%
masterFile  = %dir%\MasterListing.txt
m          := {}
FileRead, master, %masterFile%
For each, line in StrSplit(master, "`n", "`r")
 part := StrSplit(line, "="), m[Trim(part.1)] := Trim(part.2)
FileRead, text, %dir%\File-1.txt
FileAppend, % m[text], %dir%\Result-1.txt
MsgBox, 64, Done, Done!

Code: Select all

dir         = %A_ScriptDir%
masterFile  = %dir%\MasterListing.txt
ini         = %dir%\MasterListing.ini
FileRead, master, %masterFile%
FileRecycle, %ini%
FileAppend, [Main]`n%master%, %ini%
FileRead, text, %dir%\File-1.txt
IniRead, text2, %ini%, Main, %text%
FileRecycle %dir%\Result-1.txt
FileAppend, %text2%, %dir%\Result-1.txt
Run, %dir%\Result-1.txt
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

Re: Match a file value with another file value

19 Dec 2022, 21:06

Great Thank! It works as expected but for the first code when the value from File-1.txt is like "1ABC" or contains other characters like a "-ABC" it does not work
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Match a file value with another file value  Topic is solved

19 Dec 2022, 21:08

You haven't said anything about that, or provided any rules or examples for it.

Code: Select all

dir         = %A_ScriptDir%
masterFile  = %dir%\MasterListing.txt
file        = %dir%\File-1.txt
out         = %dir%\Result-1.txt
m          := {}
FileRead, master, %masterFile%
For each, line in StrSplit(master, "`n", "`r")
 part := StrSplit(line, "="), m[Trim(part.1)] := Trim(part.2)
FileRead, text, %file%
FileRecycle, %out%
For k, v in m
 text := StrReplace(text, k, v)
FileAppend, %text%, %out%
Run, %out%

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: pgeugene and 168 guests