Want to box the output

I have on script1 which provide the output text...
I want to make box around that output to make it more beautiful.
As the output lines for the script1 are not fixed, I can not hard code the design pattern.
Can anyone provide me the code to make design.?

   
|---------------------------------------------|
| This is output of script1                               |
| Wel come to computer designing                 |
| Your name XYZ and qualifications are ABC |
| Thanks you                                                   |
|----------------------------------------------|                                    
 

Any other fancy design pattern can also work.
Thanks in advance,

You can use printf to make your text fixed-length:

printf "|%-50s|\n" "This is output of script"

I run the script1 by using command

sh script1.sh

And then it gives the text output which i need to keep it in box/design pattern
can anyone help.?

I'd use my TUI :smiley:

tui-header prints the blue one, tui-title prints the white one and tui-echo/tui-pritnf prints the normal ones.

Combining them like:

tui-header
tui-title "some text of yours"
tui-header

Looks like this.

You can download at: Fedora People - sea.fedorapeople.org
NOTE: Eventhough i packaged it for Fedora, the tarball works for all (to me known/used) *nix systems.
Just place the files where the README tells.

Hope this helps or made you interested :wink:

I wrote a shells script that takes the output from stdin and surrounds it with #s.

Hope this helps.

#!/bin/bash
#
#

# read from stdin and dump to a temporary file
TMPFILE="/tmp/${0##*/}.$$"
while read -r INPUT
do
    echo $INPUT >> $TMPFILE
done

# get the length of the longest line
END=$(cat $TMPFILE | awk '{if(length($0)>l) l=length($0);}END{print l}')

# add 1 to our end length
LASTCHAR=$(expr $END + 1)

# create header and footer
FHLENGTH=$(expr $LASTCHAR + 5)
HEADER=$(seq -s "#" "$FHLENGTH" | sed 's/[0-9]//g')
FOOTER=$(seq -s "#" "$FHLENGTH" | sed 's/[0-9]//g')

# make the output pretty
echo $HEADER
while read OUTPUT
do
    printf "%1s %-${LASTCHAR}s %1s\n" "#" "$OUTPUT" "#"
done < $TMPFILE
echo $FOOTER

# done
rm -f $TMPFILE
exit 0

Run like so:

./script1 | ./makePretty.sh

a9324ffc1b2c8e0f80569337f0607756

1 Like

A DEMO that you can play with:-

Hi.

A command available on Debian-related systems: boxes

#!/usr/bin/env bash

# @(#) s1	Demonstrate enclose text within text box, "boxes".

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C boxes

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

pl " Results:"
boxes $FILE

exit 0

producing:

% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny, workstation) 
bash GNU bash 3.2.39
boxes version 1.0.1a

-----
 Input data file data1:
I have on script1 which provide the output text...
I want to make box around that output to make it more beautiful.
As the output lines for the script1 are not fixed, I can not hard
code the design pattern.
Can anyone provide me the code to make design.

-----
 Results:
 +-------------------------------------------------------------------+
 | I have on script1 which provide the output text...                |
 | I want to make box around that output to make it more beautiful.  |
 | As the output lines for the script1 are not fixed, I can not hard |
 | code the design pattern.                                          |
 | Can anyone provide me the code to make design.                    |
 +-------------------------------------------------------------------+

Additional information at Linux / Unix Desktop Fun: Text Mode ASCII-art Box and Comment Drawing

Best wishes ... cheers, drl

What about trying sth like dialog or whiptail ?

in2nix4life , This is awesome, runs pretty well in bash, is there a ksh version of it. Thanks a lot..

@rveri: would an awk- version be sufficient?

awk     '       {Arr[NR]=$0; L=length($0); if (L>MAXL) MAXL=L}
         END    {HF=sprintf("%*s",MAXL+4," "); gsub(" ","#",HF)
                 print HF
                 for (i=1; i<=NR; i++) printf "# %-*s #\n", MAXL, Arr
                 print HF}
        ' file