Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

how to align report headers in awk

👤 Login to reply

    #1  
Old 10-15-2005
galinaqt galinaqt is offline
Registered User
 
Join Date: Oct 2005
Last Activity: 7 November 2005, 12:50 PM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
how to align report headers in awk

Is it any way exept playing with spaces (tabs don't help)
Sponsored Links
    #2  
Old 10-16-2005
zazzybob's Unix or Linux Image
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
 
Join Date: Dec 2003
Last Activity: 2 October 2017, 12:19 PM EDT
Location: /dev/null
Posts: 2,187
Thanks: 3
Thanked 25 Times in 23 Posts
Have a look at the printf command in awk - that way, you can align headers and output the way you like it.

Cheers
ZB
Sponsored Links
    #3  
Old 10-16-2005
galinaqt galinaqt is offline
Registered User
 
Join Date: Oct 2005
Last Activity: 7 November 2005, 12:50 PM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
how to align headers

I only see tabs in printf command and it doesn't help. Can somebody give me an example?
    #4  
Old 10-16-2005
reborg's Unix or Linux Image
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 14 Times in 12 Posts
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")
           }
}

Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Align or move paragraph right lostincashe Shell Programming and Scripting 18 03-22-2012 07:11 PM
Align the words Lucky123 Shell Programming and Scripting 5 11-29-2011 10:27 PM
Merging of files with different headers to make combined headers file marut_ashu Shell Programming and Scripting 1 08-07-2009 04:10 AM
Remove text between headers while leaving headers intact Trones Shell Programming and Scripting 3 12-27-2008 07:06 PM
Align Text from a file. earlepps UNIX for Dummies Questions & Answers 9 08-01-2006 08:37 AM



All times are GMT -4. The time now is 12:44 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?