No announcement yet.

Remote SSH command not working with sed

  • 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' /myfile
    to replace any line having address with address in /myfile

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

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

    sed: can't read 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' myfile
    This regex have to find "address" in your file and replace it for "address".


    • #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' /myfile"
      Mostly, any quoting method over the current would do as well, however using double quotes like above would be simpler and cleaner.


      • #4

        I am running an application on a remote server which outputs a link to a webpage. It actually runs a program and passes the link as a parameter.

        I use SSH to connect to the server and run this application. I would like to be able to automatically open this link on my local machine using a Tutuapp 9Apps Showbox browser.
        Last edited by winkibili; 03-04-21, 10:33 AM.