What line do you search for,
searchstring or addstring or both?
What to do in which case?
Your function looks only for searchstring and adds addstring behind it.
But the subject and text says a string should be added if something does NOT exist.
Speeding up could be done by NOT executing a bash shell with command / function for every single file name found. Have find write all file names to a temp file, and read that in a while loop, callig the function from within - if a function is needed at all. grep ping and sed ding the same file means read / process it twice - use sed only to process it once. And, on top of what MadeInGermany already stated, you need to specify the position where to add the addstring if searchstring is missing, unless that were end-of-file.
Thanks. Inside the sed command is '\n' which inserts a new line. So I really don't get your point, the string is added on a new line if the searchString is not found. DId I misunderstand your statement?