perl -i.orig -p -e 's/^(#!.+)$/$1Add this line/' file [download]
In reply to Re: To add a string to the content of a file by johnnywang in thread To add a string to the content of a file by Babambar