Replacing text in a file from a shell script

while automating a flow, it could come in handy to replace sometimes some text or the complete line in a configuration file. This can de done easely on your mac via a shell script with the use of the sed command.

An example

Suppose you have following and want to replace the text [upcoming release] with an actual version number instead.


# [upcoming release]
- fixed flow issue

# 1.1.0
- fixed layout issue

# 1.0.0
- initial release

Following command will update the text [upcoming release] with 2.0.0.

sed -i -e 's/\[upcoming release\]/2.0.0/g'

In order to automate it even further, you could create a shell script that uses one input argument, the version number.

Automation via shell script

Create a file with name and following content:

sed -i -e "s/\[upcoming release\]/$VERSION_NUMBER/g"

Now you can run the command by executing sh 2.0.0.


If you need more information about this command, consult the manual.

man sed