Append text to file if it doesn’t exist Sed terminal

Assume you wanted to add the text “mytext” to a file if it doesn’t exist:

sed -zi '/mytext/!s/$/mytext/' /path/to/input/file

-i writes the output to the input file. If this isn’t specified, output is written to stdout