Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The -i signifies inline editing and also will have sed automatically creates a backup file. If you want to specify the suffix of the backup file you may add .suffix. For example to create the backup file with the extension .baksedautobck,

Code Block
languagebash
sed -i.baksedautobck 's/cow/reindeer/' hey.txt

...

Code Block
languagebash
sed -i.baksedautobck 's/coy/reindeer/' hey.txt
cmp -s hey.txt hey.txt.baksedautobck && echo "sed did not work, your files are identical."
sed did not work, your files are identical.

This time I do it right,

...

languagebash

...

With the mistake you get the extra third line, "sed did not work, your files are identical.".

And if we want to be more fancy to make the cmp line more generic,

Code Block
languagebash
sed -i.baksedautobck 's/coy/reindeer/' hey.txt
cmp -s $_ $_.baksedautobck && echo "sed did not work, your files are identical."

...