By Keith Mitnick on Wednesday, 22 June 2016
Category: General

Using the sed command to find and replace words in a file

This is a sed command to replace the word false with true in the updates.xml document.

sed -i "" 's/false/true/' /Users/work/Desktop/updates.xml 

Here is a breakdown of the above command.


The -i will edit the file in place.

The "" will get around not having an extension after the -i as required by os x.  

You could also use sed -i.bak which would create a backup of the file before it’s edited instead of the "".

The remainder of the command:  replace “false” with “true” in the file updates.xml. 

You could add a “g” to the command to replace all instances of false with true in the updates.xml document with the command below.

sed -i "" 's/false/true/g’ /Users/work/Desktop/updates.xml

Leave Comments