The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Align Text from a file. earlepps UNIX for Dummies Questions & Answers 9 08-01-2006 05:37 AM
C Headers biosdos High Level Programming 0 01-22-2006 11:48 AM
align several fields and fill spaces with zero DebianJ Shell Programming and Scripting 2 11-23-2005 04:51 AM
How to underline/bold and how to align output clara UNIX for Dummies Questions & Answers 1 06-16-2005 09:41 AM
kernel-headers rpm Negm Linux 2 04-05-2005 04:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-15-2005
Registered User
 

Join Date: Oct 2005
Posts: 4
how to align report headers in awk

Is it any way exept playing with spaces (tabs don't help)
Reply With Quote
Forum Sponsor
  #2  
Old 10-16-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Have a look at the printf command in awk - that way, you can align headers and output the way you like it.

Cheers
ZB
Reply With Quote
  #3  
Old 10-16-2005
Registered User
 

Join Date: Oct 2005
Posts: 4
how to align headers

I only see tabs in printf command and it doesn't help. Can somebody give me an example?
Reply With Quote
  #4  
Old 10-16-2005
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,644
You could do it something like this:, and pipe your report through it.

Code:
#! /bin/nawk -f

BEGIN{
           maxf = 0
}
{
           for(i=0;i<=NF;i++){
                     arr[NR,i] = $i
                     if ( NF > maxf ) maxf = NF
                     if ( length($i) > maxl[i] ) maxl[i] = length($i)
           }
}
END{
           for(x=0;x<=NR;x++){
                     for(y=0;y<=maxf;y++){
                               printf("%-"maxl[y]"s ", arr[x,y])
                     }
                     printf("\n")
           }
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0