0

I am using a Linux container on CircleCI with an image of circleci/node:11.14.0 and coming across an error when trying to run a sed command.

Code:

sed -i 's/<script>!f.*"dataLayer")<\/script>/<meta name="robots" content="noindex,nofollow,noimageindex,noarchive" \/>/' build/index.html
sed -i 's/<noscript><iframe.*iframe><\/noscript>//' build/index.html

Error:

sed: -e expression #1, char 1: unknown command: `.'
sed: -e expression #1, char 1: unknown command: `.'

I can run this without errors on my Mac (need to add '.bak' after -i), so I am not understanding why it doesn't work on CircleCI? I have tried to escape the special characters without any luck.

Charklewis
  • 4,427
  • 4
  • 31
  • 69
  • Why is there a `Linux: ` in front of the error message? It should work as it is, the script is ok - search somewhere else. How do you execute it? – KamilCuk Sep 27 '19 at 21:26
  • I execute it in a bash script, by calling ./scripts/my_script_file – Charklewis Sep 27 '19 at 21:29
  • 4
    If you have `/` characters in the pattern, it is typical to use a different delimiter. eg `sed -e 's@ – William Pursell Sep 27 '19 at 21:30
  • Thank you @WilliamPursell, that worked perfectly. Are you able to explain why? I assume it has something to do with the conflicting characters. – Charklewis Sep 27 '19 at 21:35
  • Both of these commands work fine for me as is. Which version of `sed` are you using? – Graeme Sep 27 '19 at 21:49
  • I’m not sure - which ever version is used for the Linux container (last checked 28/9/19). – Charklewis Sep 28 '19 at 07:04

0 Answers0