Want to box the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to box the output
# 1  
Old 10-02-2013
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.?

Code:
   
|---------------------------------------------|
| 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,
# 2  
Old 10-02-2013
You can use printf to make your text fixed-length:
Code:
printf "|%-50s|\n" "This is output of script"

# 3  
Old 10-02-2013
I run the script1 by using command
Code:
sh script1.sh

And then it gives the text output which i need to keep it in box/design pattern
can anyone help.?
# 4  
Old 10-02-2013
I'd use my TUI Smilie

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

Combining them like:
Code:
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 Smilie
Want to box the output-demo2-previewjpg
Want to box the output-demo3-box-examplejpg
# 5  
Old 10-02-2013
I wrote a shells script that takes the output from stdin and surrounds it with #s.

Hope this helps.

Code:
#!/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

Last edited by in2nix4life; 11-12-2013 at 01:45 PM..
This User Gave Thanks to in2nix4life For This Post:
# 6  
Old 10-02-2013
# 7  
Old 10-02-2013
Hi.

A command available on Debian-related systems: boxes
Code:
#!/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:
Code:
% ./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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting stdout output to whiptail menu box

As a result of whiptail menu option I am getting a data from a file. Naturally it is output to terminal as stdour. I like to redirect the output back to the menu. It can be done with single input of line of text , see attached. I just cannot see where or how the sample... (0 Replies)
Discussion started by: annacreek
0 Replies

2. How to Post in the The UNIX and Linux Forums

Copying , renaming the file from windox box and ftp to Linux box

Hello my dear friends, Two file are auto generated from mon - fri at different directories on same windows box.Every day i have to copy the file, rename it (specific name)and ftp it to linux box specified directory. is it possible to automate this process,If yes this has to be done from windows... (1 Reply)
Discussion started by: umesh yadav
1 Replies

3. Shell Programming and Scripting

Notify when the script run(hourly)on my jump-box only when there is a failure on my remote-box

Team, Presently I have a script, which i have set up cron on one of my Jump-boxes,and gives me the output on every hourly basis,fetching the data from the remote machine.Basically it gives me the list of all active users logged and its count once we execute the script.Here the count is... (6 Replies)
Discussion started by: whizkidash
6 Replies

4. Red Hat

How to access redhat Linux box graphically from windows box?

Hi I have a linux box and need to access from windows graphically # uname -a Linux pc-l416116 2.6.18-155.el5 #1 SMP Fri Jun 19 17:06:47 EDT 2009 i686 i686 i386 GNU/Linux What components do I need to install on Linux and windows to do that? TIA (6 Replies)
Discussion started by: magnus29
6 Replies

5. Web Development

How to copy a selected value of list box into a text box in html form?

hi, i have a list box , a text box and a button in a html form. list box displays some values, when a user selects a value from the list box and press the button. the selected value should be copied to the text box value. can any1 give me a html and javascript code to do this facility. ... (1 Reply)
Discussion started by: Little
1 Replies

6. Shell Programming and Scripting

ftp file starting with particular name on Windows box to Unix box using shell script

Hello all ! I'm trying to write a shell script (bash) to ftp a file starting with particular name like "Latest_" that is present on a Windows box to UNIX server. Basically I want to set this script in the cron so that daily the new build that is posted on the Windows box can be downloaded to the... (2 Replies)
Discussion started by: vijayb4u83
2 Replies

7. Solaris

Need to copy printers from Sol8 box to Sol10 box-No luck so far

I need to copy the printers currently installed on a Sol8 box to a Sol10 box. I tried copying the printers.conf file from the Sol8 box and that worked until I went through the file and changed the server name to that of the Sol10 box. Another post on this forum suggested copying the entire... (1 Reply)
Discussion started by: todis
1 Replies

8. UNIX for Advanced & Expert Users

VPN client (windows Box),and Server (Unix Box)

If I want to access unix box via VPN tunnel,from windows box. What sould I configure on the windows client PC, and what should I enable on the Unix Server box ? I am using Solaris V10 intel platform, and I am using windows XP, and 2003 for client (0 Replies)
Discussion started by: zillah
0 Replies

9. UNIX for Dummies Questions & Answers

Changing persmissions for output file in UNIX box with SQR.

I am trying to change permissions on an output file from an sqr. The file is pushed out into a directory on the unix box. I am using the following code in the sqr to accomplish this. if $OUTPUT <> '' let $unix_call = 'chmod 664 '||$OUTPUT show $unix_call CALL SYSTEM Using... (1 Reply)
Discussion started by: evengetsteven
1 Replies
Login or Register to Ask a Question