Scan files and pick overlapped hex codes
Repeating the match can be avoided by storing it in a variable first:

match = re.search(r'^0[xX][0-9a-fA-F]+', line)
if match:
    event_codes.add(match.group())


Note also that you don't need to strip a trailing \, because it is ignored afterwards anyways and you are only interested in hex codes at the beginnings of the line and all your multilines seem to have some whitespace at the beginning of the continued line. Note that you could have used re.match(r'0[xX][0-9a-fA-F]+', line), instead of re.search, because it always matches only the beginning of the line.

Python also caches your regex, once you have used it, but you may still squeeze out a bit of performance with re.compile.

I also used the match.group() method, which immediately returns the matching part if the string.



I would also not suggest caching the file content of all the files in the directories. This seems like a huge waste of memory. Instead process them one at a time and add it to your event code sets, or even better, just generate a stream of event codes that you can consume with set:

import os
import sys
import re

def event_codes_file(path):
    with open(path) as file:
        for line in file:
            match = re.match(r'0[xX][0-9a-fA-F]+', line)
            if match:
                yield match.group()

def event_codes_dir(dir):
    for root, dirs, files in os.walk(dir):
        for name in files:
            if name.endswith('Efile'):
                path = os.path.join(root, name)
                yield from event_codes_file(path)

if __name__ == "__main__":
    event_codes1 = set(event_codes_dir(sys.argv[1]))
    event_codes2 = set(event_codes_dir(sys.argv[2]))

    overlap_event_codes = event_codes1 &amp; event_codes2
    print(overlap_event_codes)


yield from x was introduced in Python 3.3 and is mostly equivalent to for i in x: yield i.

Also note that name in ('Efile') is almost the same as name == 'Efile', but matches a bit more (like 'E'). Unless of course you meant what you wrote in process_cache, name.endswith('Efile'). I am assuming the latter.

On a file "test", containing your example content, this produces:

set(event_codes_file("test"))
# {'0x00010d35', '0x04b60ff6', '0x84900c5'}