I'm big on scripted file edits using POSIX
ex rather than
sed -i and co. The big trick of course is how to ensure
ex doesn't hang waiting for input if an error is encountered.
I just wrote a comment about the possibility of using
ex to edit a file conditionally, and only save a backup of the file if edits were made.
It seems that if there were some option which could be used to tell
ex "In case of any error,
q!" then this would be fairly simple conceptually:
ex -sc '%s/pattern/replace/g | !cp % %.bup' -cx file
Of course that copy command will fail on any special characters in the filename, but you get the concept; a better form would be:
ex -sc '/pattern/ | w %.bup' -c '%s//replace/g | x' file
Essentially what I'm asking for is a form of conditional logic in
ex batch scripting, such that "If this pattern isn't found,
q!; otherwise continue."
How can I do this with