I am using the following to search a directory recursively for specific string and replace it with another:
grep -rl oldstr path | xargs sed -i \'s/oldstr/ne
I think that without using -exec
you can simply provide /dev/null
as at least one argument in case nothing is found:
grep -rl oldstr path | xargs sed -i 's/oldstr/newstr/g' /dev/null
Not sure if this will be helpful but you can use this with a remote server like the example below
ssh example.server.com "find /DIR_NAME -type f -name "FILES_LOOKING_FOR" -exec sed -i 's/LOOKINGFOR/withThisString/g' {} ;"
replace the example.server.com with your server replace DIR_NAME with your directory/file locations replace FILES_LOOKING_FOR with files you are looking for replace LOOKINGFOR with what you are looking for replace withThisString with what your want to be replaced in the file