This looks can be refactored to a common method e.g. read_replace_script(filename, hash_sub)