Center a string using awk
awk = everyone’s favorite - right?
People who know me also know that I prefer simple
universally available tools to get a job done. Awk is
probably one of my favorites because it does pretty
much anything I need for quick and simple jobs. It is
far more powerful than most people realize including
associative arrays and it will do anything grep and sed
can do.
Recently I had the need to center a string of text. This is a easy problem that pretty much any freshman programmer can accomplish in a heartbeat but I decided to do it with awk. This sample gives you a chance to explore rudimentary features of awk.