Task

Replace every occurring instance of a piece of text in a group of text files with another one.



For this task we want to replace the text   "Goodbye London!"   with   "Hello New York!"   for a list of files.




replace() {
    local search=$1 replace=$2
    local file lines line
    shift 2
    for file in "$@"; do
        lines=()
        while IFS= read -r line; do
            lines+=( "${line//$search/$replace}" )
        done < "$file"
        printf "%s\n" "${lines[@]}" > "$file"
    done
}
replace "Goodbye London!" "Hello New York!" a.txt b.txt c.txt