Tutorial by Examples

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 b...
In-place editing, while common, is a non-standard feature. A viable alternative would be to use an intermediate file to either store the original, or the output. sed 'sed commands' > file.out && mv file.out file # or mv file file.orig && sed 'sed commands' file.orig > file ...
sed -i -e cmd file will modify file even if its permissions are set to read-only. This command behaves similarly to sed -e cmd file > tmp; mv -f tmp file rather than sed -e cmd file > tmp; cat tmp > file; rm tmp The following example uses gnu sed: $ echo 'Extremely important data' &gt...

Page 1 of 1