Formatting output alignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting output alignment
# 1  
Old 06-23-2010
Question Formatting output alignment

Hi Gurus,

I've the following output from my scripting as shown below.

Code:
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 alignment?

Please kindly advice. Thanks.


Regards,
Peter
# 2  
Old 06-23-2010
only modify the positions as you like..

Code:
awk '{printf "%-8s%-3s%-8s%-3s%-8s%-3s%-5s\n", $1,$2,,$3,$4,$5,$6,$7}' IN_FILE

# 3  
Old 06-23-2010
What is the desired output? To remove the double spaces you can do sommething like:
Code:
command | awk '$1=$1'

This User Gave Thanks to Franklin52 For This Post:
# 4  
Old 06-23-2010
hi

you can try this

Code:
# sed -e '1,2s/GB[^*]/  GB \t/g' -e '1,2s/\([0-9]*%\)/  \1/' output

# 5  
Old 06-23-2010
Try this:
Code:
awk -vn=`awk '{for (i=1;i<=NF;i++) if (m<=length($i)) m=length($i)}END{print m}' file` \
'{for (i=1;i<=NF;i++) {if ($i~"GB") {printf ("%s", " GB")} else printf ("%"n"s",$i);} printf "%s","\n"}' file

This User Gave Thanks to bartus11 For This Post:
# 6  
Old 06-23-2010
Hi albertogarcia,

Thanks for your response.

Your method works, but the alignment is not as expected. Please see below.

Output:
Code:
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%

Desired output:
Code:
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 the output into above alignment?

Thanks.



Regards,
Peter
# 7  
Old 06-23-2010
Alignment to the right for better readability and easier comparing of the sizes:

Code:
$> awk -F "B" '{gsub(/ +/," "); printf "%14s%1s%14s%1s%14s%1s%10s\n", $1, FS, $2, FS, $3, FS, $4}' infile
        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%

This User Gave Thanks to zaxxon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Formatting the Output

Hi, I am trying to use printf command and format certain output in a specific format as under: While the left side (upto |) of the above format is part of a fixed header function, the right side is where i am expecting data to be printed. However, as seen, Row1 value is reflecting on last... (5 Replies)
Discussion started by: EmbedUX
5 Replies

3. UNIX for Dummies Questions & Answers

Formatting df output

Hi all, Can anyone please suggest how best to handle output from running df where some of the information for a volume/filesystem spread over two lines? Some of my volume/filesytem are NFS mounted and when I run a df, the information is spread over the two lines instead of the usual norm... (4 Replies)
Discussion started by: newbie_01
4 Replies

4. Shell Programming and Scripting

Output formatting .

below is a CPU utilization Log for ABC server. However for every 15 minutes it generates 3 CPU values(with interval of 2 sec). Host CPU CPUtotal CPU% time ABC 101.1 2 50.55 14 : 15 ABC 100.5 2 50.25 14 : 15 ABC 100.2 2 50.1 14 : 15 ABC 100.9 2 50.45 14 : 30 ABC 100.5 2 50.25 14 : 30 ABC... (5 Replies)
Discussion started by: pinga123
5 Replies

5. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: thriloka
1 Replies

6. Shell Programming and Scripting

Formatting of output

Hi Experts, I have to create a report for certain audit and my output looks as follows I m trying to format my output to look like Any inputs would be highly appreciated Thanks Syed (5 Replies)
Discussion started by: maverick_here
5 Replies

7. 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

8. Shell Programming and Scripting

formatting output

my script is as follows cnt=`ps -ef |grep pmon|grep -v grep|awk 'END {{print NR}}'` cnt2=`ps -ef |grep tns|grep -v grep|awk 'END {{print NR}}'` if then if then rman target/ catalog recdb/recdb@recdb cmdfile report_need_backup.sql > report_need_backup.txt ... (1 Reply)
Discussion started by: swkambli
1 Replies

9. Shell Programming and Scripting

formatting the output

Is it possible to convert the attached file to the format mentioned. Here for a particular job the table name and the corresponding instance name from one test run "X" is compared with the table name and the instance name from the second test run "Y" for output rows,affected rows,applied... (1 Reply)
Discussion started by: ragavhere
1 Replies

10. 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
Login or Register to Ask a Question