title: How to run sed on remote server using ssh inside a shell script(variables included)
body: <p>I have a situation here, I am trying to run a sed command on a remote shell inside my shell script and using variables that are dynamic and end up getting the same error again and again.</p>
  
  <p>This is the sed command that is running fine on local shell without any error. I have used this regular expression after thorough testing and trust me there is no problem with it.</p>
  
  <pre><code>sed -i 's/  #0\t30718/ 0\t30718/' ./config.txt
  </code></pre>
  
  <p>Trying to run this in a remote shell using ssh:</p>
  
  <pre><code>ssh root@sys_name sed -i 's/  #0\t30718/ 0\t30718/' /absolute-path/vconfig.txt
  </code></pre>
  
  <p>And when I try to run this command using variables. (30718 and path of the file are the variables):</p>
  
  <pre><code>ssh root@sys_name 'sed -i "s/0\t${pe_list[0]}/#0\t${pe_list[0]}/g" $file_path'
  </code></pre>
  
  <p>or like this:</p>
  
  <pre><code>ssh root@sys_name "sed -i 's/0\t${pe_list[0]}/#0\t${pe_list[0]}/g' $file_path"
  </code></pre>
  
  <p>I either get the <em>sed: -e expression #1, char 2: unterminated `s' command</em> error or the sed command executes with undesired output matching the variable names as is. Basically, put in few words, I want to execute a sed command on a remote shell using ssh, and the constraint is that the entire command is part of a script and the values to be matched and the filename are variables in that file.</p>