Artificial intelligent assistant

More elegant approach to append text to a file only if the String doesn't exist? I want to append NoDisplay=true to a .desktop file, but only if the entry doesn't exist. I do this the following way: grep -q 'NoDisplay=true' '/usr/share/applications/yelp.desktop' || bash -c 'echo "NoDisplay=true" >> /usr/share/applications/yelp.desktop' I was wondering if there is a shorther oneliner for the same operation? I use this command in a bash script and had to use command "bash -c".

If you have GNU `sed`, it's fairly simple:


sed -zi '/NoDisplay=true/!s/$/\
NoDisplay=true/' file


Option `-z` treats the whole line at once in the pattern space (not recommended for huge files). If the setting is not (`!`) found, append it at the end with an embedded newline. Note: `-i`, `-z` and `\
` in the replacement string are not standard, so this is not portable.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 132dc2f93716680e2810cf764a6e198e