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"