-1

My goal was to replace (in place) any instance of

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

with

src="http

Inside of an html file. The catch: I need to use AppleScript to do this. The code is as follows:

set myfile to "pathto/test.html"

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

This gives the error:

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

I'm not sure what this error means...hope someone can help!

  • Possible duplicate of [sed command with -i option failing on Mac, but works on Linux](https://stackoverflow.com/questions/4247068/sed-command-with-i-option-failing-on-mac-but-works-on-linux) – Wiktor Stribiżew Oct 24 '18 at 23:22
  • I just want to edit the file in place. I don't want to have to create a backup. How should I modify this to make it work? – Patrick Hennessey Oct 24 '18 at 23:30
  • You do not need to create any backup, add `''` after `-i`. See https://stackoverflow.com/a/14813278/3832970 – Wiktor Stribiżew Oct 24 '18 at 23:30
  • It still won't work. sed -i'' 's/src=\"*.+http/src=\"http/g' pathto/test.html Still fails. – Patrick Hennessey Oct 24 '18 at 23:35
  • Have you read that thread? There are at least 3 options how to do that. – Wiktor Stribiżew Oct 25 '18 at 06:50
  • I need to use AppleScript because it is part of a workflow. Yes, I read the thread. The reason it wasn't working was because you can't use a regex with a + symbol unless you use -E, which was not part of that thread. It also doesn't work on OSX unless you specify a backup. Edit in place does not work on OSX. – Patrick Hennessey Oct 25 '18 at 17:45

1 Answers1

0

This worked:

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

There has to be a space after the -i.