Jun 212010
Replace infile using sed and make a backup automatically
Answer:
If you use the -i flag in sed, it will replace infile, which is quite dangerous if you don't have a backup.
E.g.
# sed -i 's/foo/bar/gi' input.txt
To auto make a backup when replacing in a file, you can use
# sed -i.bak 's/foo/bar/gi' input.txt
Now the original file will stored as input.txt.bak in the same directory that you are working.