/bin/echo "%s/STRING1/STRING2/g\nwq!" | ex -s FILE # | | | # V V V # replace by in file