Skip to content

Instantly share code, notes, and snippets.

@jxc876
Last active March 4, 2025 17:08
Show Gist options
  • Save jxc876/5813b2606a8ea63ae7bab9f55e85e1b2 to your computer and use it in GitHub Desktop.
Save jxc876/5813b2606a8ea63ae7bab9f55e85e1b2 to your computer and use it in GitHub Desktop.
Reddit 1j2tfr2 (version 3)

About

Answer to

# version 3
import re


def main():
    file_one = 'file-1.txt'
    file_two = 'file-2.txt'

    word_tuples = []

    with open(file_one, 'r') as file:
        for line in file:
            words = line.split()  # splits on white space
            word_tuples.append((words[0], words[1]))

    new_lines = []
    with open(file_two, 'r') as file:
        for line in file:
            # Look for StaticMesh lines
            match = re.search(r"StaticMesh=?'(.+)'", line)
            if not match:
                new_lines.append(line.strip())
                continue

            quoted_word = match.group(1)

            # see if any of the lines from file 1 match it
            was_found = False
            for word_tuple in word_tuples:
                if word_tuple[0] == quoted_word:
                    new_lines.append(line.replace(quoted_word, word_tuple[1]))
                    was_found = True
            if not was_found:
                new_lines.append(line.strip())

    for new_line in new_lines:
        print(new_line)


if __name__ == '__main__':
    main()

Run this as :

python3 main.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment