Shell script output alignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script output alignment
# 1  
Old 03-21-2011
Shell script output alignment

Hi

How can I alaign the output of a script.

Exaplme

my script has assigned values to two variables, VAR1 and VAR2


VAR1=This is RAJ working as a DB2 UDB DBA for VISA Corporation, Need your help in Shell scripting

VAR2= This is RAM working as a ORACLE DEVELOPER for TARGET Corporation, Need your help in Shwll scripting, Thanks in Advance for your reply.

and the output should be
Code:
-------------------------------------------------------------------------
| VAR1                              | VAR2 |
-------------------------------------------------------------------------
|This is RAJ working as DB2 | This is RAM working as a |
|UDB DBA for VISA            | ORACLE DEVELOPER for TARGET |
|Corporation, Need your     | Corporation, Need your help in |
|help in Shell scripting         |Shell scripting, Thanks in Advance |
|                                     | for your reply. |
|-------------------------------------------------------------------------


Last edited by pludi; 03-21-2011 at 07:01 AM.. Reason: alignment issue
# 2  
Old 03-21-2011
Hi.

One solution, assuming you want text in evenly-spaced columns:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate fold, paste and expand to columnize text.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
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 fold paste expand

# VAR1=This is RAJ working as a DB2 UDB DBA for VISA Corporation,
# Need your help in Shell scripting
# VAR2= This is RAM working as a ORACLE DEVELOPER for TARGET
# Corporation, Need your help in Shwll scripting, Thanks in Advance
# for your reply.

v1="This is RAJ working as a DB2 UDB DBA for VISA Corporation, Need your help in Shell scripting"

v2="This is RAM working as a ORACLE DEVELOPER for TARGET Corporation, Need your help in Shwll scripting, Thanks in Advance for your reply."

pl " Results:"
paste <( echo "$v1" | fold -s -30 ) <( echo "$v2" | fold -s -30 ) |
expand -35

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.7 (lenny) 
GNU bash 3.2.39
fold (GNU coreutils) 6.10
paste (GNU coreutils) 6.10
expand (GNU coreutils) 6.10

-----
 Results:
This is RAJ working as a DB2       This is RAM working as a 
UDB DBA for VISA Corporation,      ORACLE DEVELOPER for TARGET 
Need your help in Shell            Corporation, Need your help 
scripting                          in Shwll scripting, Thanks in 
                                   Advance for your reply.

See man pages for details. Adjust numbers to suit your desires.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

4. Shell Programming and Scripting

Coloring cli output, screws up 'alignment'

Heyas I'm trying to add color 'support' to my TUI. It works, but behaves weird. Code in question: (status.conf) R="\033" ; TUI_WORK="" TUI_DONE="" ; TUI_FAIL="" TUI_SKIP="" ; TUI_NEXT="" TUI_BACK="" ; TUI_CANC="" TUI_ON="" ; TUI_OFF="" TUI_INFO="" ; TUI_HELP="" The... (4 Replies)
Discussion started by: sea
4 Replies

5. Shell Programming and Scripting

Output alignment problem

Hi Gurus, This is my raw data. How would I able to format this output into a better alignment? /dev/vg00/lvol5 /home 0.12 GB 0.02 GB 0.10 GB 19% /dev/vg00/misc /misc 28.43 GB 4.92 GB 23.51 GB 17% /dev/vg00/lvol6 /opt 8.25 GB 5.43 GB 2.82 GB 65% /dev/vgsap/ora10264 ... (10 Replies)
Discussion started by: superHonda123
10 Replies

6. Shell Programming and Scripting

Formatting output alignment

Hi Gurus, I've the following output from my scripting as shown below. 0.48 GB 0.29 GB 0.19 GB 60% 0.48 GB 0.29 GB 0.19 GB 60% 228.90 GB 89.47 GB 139.42 GB 39% 228.76 GB 72.37 GB 156.39 GB 31% Is it possible to format this output into a proper... (16 Replies)
Discussion started by: superHonda123
16 Replies

7. Shell Programming and Scripting

[How To?] Run shell script and get output into another shell.

Hi guys, I have a simple question, I want to store the output of the following command: As you can see it is running all the time, and we get a new line every 3sec. I just want to store these new lines into a single variable, so I can use it into a script. To clear the screen, and... (4 Replies)
Discussion started by: Thireus
4 Replies

8. Shell Programming and Scripting

how to get the correct alignment in a textfile to a mail using shell script?

Hi All, Can any one solve this prob. Im sending a textfile content as a mail body while sending a mail using shell script. But, that textfile content is a unic command output. So, in mail, im not getting the correct alignment as in textfile. What may be the reason behind this. Can... (1 Reply)
Discussion started by: suman_dba1
1 Replies

9. Shell Programming and Scripting

output display alignment !!

Hi I'm trying to display the output of my script in a friendly viewable format. it's something like this.. i have this while loop... in which i get some records from a file where fields are delimitered with a pipe. so i'm extacting each field and replacing the pipe with a \t, tab !!.. cat... (7 Replies)
Discussion started by: rosh0623
7 Replies

10. UNIX for Advanced & Expert Users

alignment in shell script

grep 'Dept' x.lst |awk -F"Name=" `{print $1" "$2" "$3}` the output is coming like this Krishna 1 2340 8383 Rohan 10 982 234 how can I align these numbers using shell script. even i used typeset but it is useful for only zero-when-blank.... (1 Reply)
Discussion started by: krishna
1 Replies
Login or Register to Ask a Question