How to insert a line into text document right before line containing some text in bash?

view full story

http://unix.stackexchange.com – I have a variable say $strToInsert I have a file file.html I wonder how to find last appearence of </head> and insert a new line before line with it and fill it with $strToInsert contents? Update: Here is what I have: GACODE="UA-00000000-1" if [ "$2" = "" ] then echo "Usage: $0 <url to extract doxygen generated docs into> <GA tracker code if needed>" echo "Using default" else GACODE = $2 fi GASTR="<script>var _gaq = _gaq || [];_gaq.push([\'_setAccount\', \'$GACODE\']);_gaq.push([\'_trackPageview\']);(function() {var ga = document.createElement('script') (HowTos)