- 1) On linux, we can use:
If file don't exist, no empty file will be created. But that will not work on some systems, as example freebsd.
Code: Select all
sed -i 'sed command' file
- 2) On both linux and freebsd, we can add a .suffix to -i:
If file don't exist, no empty file will be created.
Code: Select all
sed -i.bak 'sed command' file
- 3) It is not in place editing but the result is the same, and it is the safest way to do it - on both linux and freebsd, we can use redirection and a temporary file:
or
Code: Select all
sed 'sed command' file > file.tmp mv -f file.tmp fileIf file don't exist, that will create an empty file, which can cause nasty bugs. That imply it is best and necessary to test if file exist and run these 2 commands only if it exist.Code: Select all
sed 'sed command 1' file > file.tmp sed 'sed command 2' file.tmp > file



