sed In-Place Editing Replacing strings in a file in-place


Example

sed -i s/"what to replace"/"with what to replace"/g $file

We use -i to select in-place editing on the $file file. In some systems it is required to add suffix after -i flag which will be used to create backup of original file. You can add empty string like -i '' to omit the backup creation. Look at Remarks in this topic about -i option.

The g terminator means do a global find/replace in each line.

$ cat example 
one
two
three
total
$ sed -i s/"t"/"g"/g example 
$ cat example 
one
gwo
ghree
gogal