Si vous devez modifier le contenu des fichiers instantanément, vous pouvez utiliser la fonction sed -e 's/your/expression/g' -i filename
. Vous pouvez ajouter un -i.bak
pour sauvegarder le fichier original avant toute modification.
Ajoutant, que sed
es un Éditeur de flux et vous devriez plutôt utiliser ed
o ex
.
Exemple de mise à jour :
[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
Voir comment -i.bak
crée automatiquement un fichier de sauvegarde pour nous protéger contre le risque d'écraser le fichier par accident.
Voir lin http://wiki.bash-hackers.org/howto/edit-ed pour des exemples utilisant le ed
éditeur.