You can make in-file changes by using the -i
option.
$ sed '/dog/i\ Linux Scripting' animals
Linux Scripting
dog
cat
dolphin
cat
$ sed -i '/dog/i\ Linux Scripting' animals
$ cat animals
Linux Scripting
dog
cat
dolphin
cat
From the man
page:
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
So you can create a backup of your original file by passing a suffix. This can be done by saying:
sed -i.bak '/dog/i\ Linux Scripting' animals
This will make in-file changes to your animals
file but will create animals.bak
file if you ever need the original file.