问题描述:

I am trying to replace a string in my shell script from localhost:7101/RPAS to sound.mojo.com:5555/rpas in my HTML file.

${myDeployment} =<\/td><\td width="0">http://localhost:7101/RPAS<\/td>

My output should be:

${myDeployment} =<\/td><\td width="0">http://sound.mojo.com:5555/rpas<\/td>

  1. The strings that are fixed are ${myDeployment} and </td> and localhost:7101 is not a fixed string.
  2. http://occurs multiple times in document and the above mentioned string occurs at the last , but not at the end of the document.
  3. Is there a way to extend this command to only change the string of the last occurring pattern in the file.

sed -e 's#>http://[^/]*/#>http://sound.mojo.com:5555\/rpas/#' tst.html

Please let me know if there is a way to do it.

网友答案:

You can use this sed command:

sed 's#>http://[^/]*/#>http://sound.mojo.com:5555#' file

${myDeployment} =<\/td><\td width="0">http://sound.mojo.com:5555RPAS<\/td>
相关阅读:
Top