Issue with user input including * (glob) and sed

Hello All,

I have created a script that searches for different things and "sanitizes" the findings from files. Currently the user is required to put in a hostname (server.serverfarm.abc) one at a time to replace. I would like the user be able to use *.*.abc in grep and then pipe into sed to make changes.

I am currently stuck on having sed actually replace grep findings that include *.*.abc

I have tried different shopt options with no success. I believe it might be how i am writing the string (escaping characters etc). If someone could take a look at this that would be great!

#Function for Hostnames
hostcheck(){
       grep -Eilrs --exclude='.*' --exclude='*.sh' *.*.abc [directory] | 
       xargs -d "\n\n" sed -i "s/$hostname/$change/Ig"
                  }

I can provide more of the script if needed. Grep finds but when piped into sed it actually doesn;t do anything.

The variables are put in by the user. They are asked a hostname and input. They are asked what will replace ($change) the $hostname. Directory is also input from the user.

Any suggestions with using sed before i move on to a different tool? thanks!

--- Post updated at 10:46 PM ---

Hello All,

The following seems to work:

grep -Eilrs --exclude='.*' --exclude='*.sh' *.*.abc | xargs -d "\n\n" sed -r "s/.*.*.abc/xx.xx.xx/Ig"

I am plugging this into the much larger script and will test from there. Once again, with many ways to skin a cat, I would be interested how i could improve upon this, thanks!

--- Post updated at 10:47 PM ---

Correction:

grep -Eilrs --exclude='.*' --exclude='*.sh' *.*.abc | xargs -d "\n\n" sed -ir "s/.*.*.abc/xx.xx.xx/Ig"

Some thoughts:

*.*.abc as used for grep seems to be a "glob" but should be a regex same as the one used in the sed script (where, BTW, the . is a wildcard char and should be escaped for the extension separator).
Simply using sed on ALL files (leaving them intact if no pattern found) might be more efficient than grep ping through all of them, and then using multiple sed invocations again on those with the pattern - depends on the average file length, and the ratio of files with vs. without pattern.
With awk , you could use one single invocation working on an input stream of all files writing to respective individual temporary output files.