From Newsgroup: comp.lang.awk
Nifty little script...
#!/bin/sh
#
# tags: box, sh, shell, awk, code
#
# box - awk shell script encases
# output within a formatted box
# Michael Sanders 2023
#
https://busybox.neocities.org/notes/box.txt
#
# example...
#
# +---------------+
# | 3 menu items |
# | |
# | . coffee |
# | . tea |
# | . iced water |
# +---------------+
awk '
{
lines[NR] = $0
current = length($0)
if (current > max) max = current
}
END { box(lines, NR, max) }
function box(ary, num, width, count) {
horizontal(width)
while(++count <= num) vertical(width, ary[count])
horizontal(width)
}
function vertical(width, line) { printf "| %-" width "s |\n", line }
function horizontal(width, x, line) {
line = "+"
for (x = 0; x < width + 2; x++) line = line "-"
print line "+"
}
' <<'DATA'
_
/ \ _-'
_/| \-''- _ /
__-' { | \
/ \
/ "o. |o }
| \ ;
',
\_ __\
''-_ \.//
/ '-____'
/
_'
_-'
DATA
# eof
--
:wq
Mike Sanders
--- Synchronet 3.20a-Linux NewsLink 1.114