Correctly replace the prefix in text files