So I created this little guy to help me out. Whenever run, he generates a date line in html that looks like this on a web page:

Last updated Wednesday December 15 2010

and updates a footer file I’ve called foot.tpl

_________update.sh

#!/bin/bash<br></br> #change the Last updated part of foot.tpl<br></br> cd /var/www/<br></br> #generate nice looking date command<br></br> DATE="$(date "+%A %B %e %Y")"<br></br> MYVAR="<p>Last updated"<br></br> END="</p>"<br></br> FINAL="$(echo $MYVAR $DATE $END)"<br></br> #we are going to look for any line that has the word updated and replace that whole line with our new one now contained in the variable FINAL<br></br> sed "<br></br> /updated/ c\<br></br> $FINAL<br></br> " foot.tpl > footnew.tpl<br></br> mv footnew.tpl foot.tpl

And thats it!  For me, the word “updated” only shows up once in my foot.tpl so the old line is completely removed and replaced with the new one.

Very useful.

Mario Loria is a builder of diverse infrastructure with modern workloads on both bare-metal and cloud platforms. He's traversed roles in system administration, network engineering, and DevOps. You can learn more about him here.