In the remote server, I can run this command:
sed -i '/address/c\address xx.xx.xx.xx' /myfileto replace any line containing address with address xx.xx.xx.xx in /myfile
However, from my local machine, this command is not working
ssh root@ip sed -i '/address/c\address xx.xx.xx.xx' /myfileIt gives the following error:
sed: can't read xx.xx.xx.xx: No such file or directoryHow to fix this problem?
2 Answers
You are preventing the expansion on the local shell, but you need to preserve everything as far as the command to run, sed in this case, on both shells.
Quote the sed command to run:
ssh root@ip "sed -i '/address/c\address xx.xx.xx.xx' /myfile"In essence, any quoting method over the current would do too, but using double quotes like above would be simpler and cleaner.
0To replace u should use sed in this way:
sed -i 's/^.*address/address yourfile
This regex should find "address" in your file and replace it for "address xx.xx.xx.xx".