This is simplified version of my actual problem. Here's my test.data file
test.data
=========
PROD SEARCH_URL = "google.com" db name "customers"
TEST SEARCH_URL = "google.com" db name "emp"
For all the lines containing "TEST", I want to change the search domain from "google.com" to "bing.com"
Below sed command works fine to achieve this:
sed -rin '/PROD/!s/bing.com/google.com/' test.data
But the way my test environment is set up, I need to run the sed command using "su" as:
su root "sed -rin '/PROD/!s/bing.com/google.com/' test.data"
And this results in error
-bash: !s/bing.com/google.com/': event not found
From other stackoverflow quesrions, I have tried: escaping ! and enclosing it in ''. Nothing seems to work
Have also tried "set +H" as below and it doesn't work:
su root "set +H && sed -rin '/PROD/!s/bing.com/google.com/' test.data"
What am I missing?