I have written several scripts -- some throwaway, some not -- that use ed. If you know what you need to do to edit a file and need it automated, ed is just super handy. Here is a shell script that deletes all comments from a yaml file, then comments out a particular key:
ed $file << COMMANDS
g/^#.\*$/d
/yaml_key:
s/^/#/
w
q
COMMANDS