If you need to modify files content instantly you can use the sed -e 's/your/expression/g' -i filename
. You can add a -i.bak
to backup the original file before any change happens.
Adding, that sed
is a Stream EDitor and you rather should use ed
or ex
.
Update example:
[val0x00ff@localhost dir1]$ ls
file
[val0x00ff@localhost dir1]$ cat file
test
anothertest
hangethisLine/g
[val0x00ff@localhost dir1]$ sed -i.bak 's/test/substitute_to_this/g' file
[val0x00ff@localhost dir1]$ ls -l
total 8
-rw-rw-r-- 1 val0x00ff val0x00ff 62 Aug 28 14:59 file
-rw-rw-r-- 1 val0x00ff val0x00ff 34 Aug 28 14:58 file.bak
[val0x00ff@localhost dir1]$ cat file
substitute_to_this
anothersubstitute_to_this
hangethisLine/g
[val0x00ff@localhost dir1]$ cat file.bak
test
anothertest
hangethisLine/g
See how -i.bak
creates a backup file automatically to protect us from overriding the file by accident.
See lin http://wiki.bash-hackers.org/howto/edit-ed for examples using the ed
editor.