Formatting output alignment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting output alignment
# 15  
Old 06-23-2010
Hi Franklin52,

I've tried to play around with the given solution, but with limited knowledge in this area, I'm unable to solve it.

That's why I need help from more experience users.

Thanks.


Regards,
Peter

---------- Post updated at 04:48 AM ---------- Previous update was at 04:46 AM ----------

Hi ygemici,

The result is still the same for more entries, however, I had been given other solution that works.

Thanks for your help.


Regards,
Peter

---------- Post updated at 05:09 AM ---------- Previous update was at 04:48 AM ----------

Hi zaxxon,

I found your method is quite interesting and have been trying to understand what does it mean and how it works.

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

Could you advice what does this section mean?
Code:
awk -F "B" '{gsub(/ +/," ")

When I tried your method with more entries, the alignment is out. But, this does not happen with fewer entries. The first column is OK, not the second and third. Could not understand why.

Code:
       28.12 GB         0.02 GB         28.10 GB        0%
        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%

Appreciate for any help and advice.

Thanks.


Regards,
Peter
# 16  
Old 06-23-2010
Quote:
Could you advice what does this section mean?
Code:
awk -F "B" '{gsub(/ +/," ")

Sure. Since your input file has no real usable field separator, I decided to use the B of GB (that's the awk -F "B") as field separator.
Between the fields is sometimes 1 blank and sometimes many more than 1 blank separating them. So I tell awk to globallysubstitute, every 2 or more blanks with a single blank. If not doing that, it happens that the sometimes plentyful blanks in your lines just push the fields further apart so that a formatting with printf is kinda ugly and not possible.

So if you check what happens when you just use the code above without the long printf, you get this:
Code:
awk -F "B" '{gsub(/ +/," "); print}' 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 a much more tidy base to start from, using "B" as field seprator. All those different amounts of spaces pushing fields apart are gone and sowith do not disturb using printf.

Last edited by zaxxon; 06-23-2010 at 12:30 PM.. Reason: adding info
This User Gave Thanks to zaxxon For This Post:
# 17  
Old 06-24-2010
Hi zaxxon,

Thanks a lot for your detailed explanation.


Regards,
Peter
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