【问题标题】:How to use sed inside AppleScript to find/replace all instances in an html file?如何在 AppleScript 中使用 sed 来查找/替换 html 文件中的所有实例?
【发布时间】:2019-03-29 11:18:02
【问题描述】:

我的目标是替换(就地)任何

的实例
src="[random text i want to remove]http

src="http

在 html 文件中。问题:我需要使用 AppleScript 来执行此操作。代码如下:

set myfile to "pathto/test.html"

do shell script "sed -i 's/src=\"*.+http/src=\"http/g' " & quoted form of myfile

这给出了错误:

sed: 1: "pathto/test.html": command c expects \ followed by text

我不确定这个错误是什么意思...希望有人能提供帮助!

【问题讨论】:

标签: macos sed applescript


【解决方案1】:

这行得通:

sed -i '' -E 's/src=\"*.+http/src=\"http/g' myfile.html

-i 后面必须有一个空格。

【讨论】:

    猜你喜欢
    • 2016-04-30
    • 2021-07-26
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2015-06-12
    • 2010-12-20
    相关资源
    最近更新 更多