:%s/word1\(.*\)word2$/word3\1word4/
Over each line in the whole file, search for word 1 and word 2 (which is at the end of the file), separated by arbitrary non-newline characters, and change them to word3 and word4.
M-x replace-regexp word1\(.*\)word2$ RET word3\1word4 RET
:%s/word1\(.*\)word2$/word3\1word4/
Over each line in the whole file, search for word 1 and word 2 (which is at the end of the file), separated by arbitrary non-newline characters, and change them to word3 and word4.