Currently I have a file that has a unique line with the pattern
alphanumeric_ChangeMe_moreAlphaNumeric
Actual looks like this:
127.0.0.1 local.com localhost HostType_test_HostNumber2
I'm trying to replace the string test with a variable determined by another command, run as another user using the following code.
site=$(su admin -c get_local_site | less | sed 's/Local Site Name: //')
sed -i -e "s/RecoverPoint_[[:alnum:]]*_RPA/RecoverPoint_$site_RPA/" fakehostfile
I've tested the individual codes and they echo the correct values, but when I try to use the $site variable in the second it fails to replace the section.
I can't seem to find the correct syntax to replace just what's between the underscores with a string (containing only alphanumerics) that's stored in a variable
I've already been looking on here, and found some similar problems, however the solutions don't seem to work, since part of the replacement string is a variable. I've tried to concatenate the string as three separate variables, but it replaces things strange (Maybe due to the underscores?)
What am I missing here??
Questions with similar problems that didn't work:
sed variable replacement does not seem to work Sed replacement not working when using variables