替换 shell 脚本中两个特殊字符之间的字符串

Replacing String Between two special charters in shell script

我正在尝试将 shell 脚本中的字符串从 localhost:7101/RPAS 替换为 HTML 文件中的 sound.mojo.com:5555/rpas。

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

我的输出应该是:

${myDeployment} =<\/td><\td width="0">http://sound.mojo.com:5555/rpas<\/td>
  1. 固定的字符串是${myDeployment}和,localhost:7101不是固定的字符串。
  2. http://occurs 在文档中多次出现,并且上述字符串出现在最后,但不在文档末尾。
  3. 有没有办法扩展此命令以仅更改文件中最后出现的模式的字符串。

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

如果有办法,请告诉我。

您可以使用这个 sed 命令:

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

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