sed: Replacing variableURLs in a file for iOS

Edgar Sanchez
1 min readApr 8, 2020

--

Today I had to write a little script to take 2 environment variables and replace the values in a text file.

The following:

sed -i "s/"${LOCALHOST_ADDRESS}"/${APIGATEWAY_ADDRESS}/g" path/to/my/file

Error out with:

sed: 1: “path/to/my/file …“: command i expects \ followed by text

To fix it I had to use

sed -i '' "s~${LOCALHOST_ADDRESS}~${APIGATEWAY_ADDRESS}~g" path/to/my/file

Notice this:

  • ‘’ the single quotes after -i which are required for the iOS
  • ~ which is required to escape the // in the URL addresses

There you have it!

--

--

Edgar Sanchez

A great architect - humble in spirit. dangerous with production access.