Announcement

Collapse
No announcement yet.

Remote SSH command not working with sed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remote SSH command not working with sed

    I can run the following command on the remote server

    sed -i '/address/c\address 11.11.11.11' /myfile
    to replace any line having address with address 11.11.11.11 in /myfile

    But, from my local system, this command is not working

    ssh [email protected] sed -i '/address/c\address 11.11.11.11' /myfile
    I'm getting the following error message

    Code:
    sed: can't read 11.11.11.11: No such file or directory
    How to fix this problem?

  • #2
    To replace you can use sed in the following way:

    sed -i 's/^.*address/address 11.11.11.11/' myfile
    This regex have to find "address" in your file and replace it for "address 11.11.11.11".

    Comment


    • #3
      You are averting the expansion on the local shell, but you have to conserve everything till the command to run, sed in this case, on both shells.

      Quote the sed command to run:
      ssh [email protected] "sed -i '/address/c\address 11.11.11.11' /myfile"
      Mostly, any quoting method over the current would do as well, however using double quotes like above would be simpler and cleaner.

      Comment

      Working...
      X