Speedup sed search and replace
If you have a very large file, sometimes you can speed up sed by using the following method:
# sed 's/foo/bar/g' filename
# sed '/foo/ s/foo/bar/g' filename
The second method is faster since substitution is only performed when the search string is found.