how to align report headers in awk

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 10-16-2005
how to align report headers in awk

Is it any way exept playing with spaces (tabs don't help)
# 2  
Old 10-16-2005
Have a look at the printf command in awk - that way, you can align headers and output the way you like it.

Cheers
ZB
# 3  
Old 10-16-2005
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
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")
           }
}


|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
awk to compare files and validate order of headers cmccabe Shell Programming and Scripting 0 04-21-2017 09:53 AM
Align columns erin00 Shell Programming and Scripting 1 12-14-2016 11:34 PM
Re align in one row using sed fspalero Shell Programming and Scripting 8 08-18-2016 02:20 PM
Align input fields on one under each other galford Shell Programming and Scripting 1 06-17-2016 06:52 PM
Align columns reignangel2003 Shell Programming and Scripting 1 07-28-2015 04:02 AM
Align data of the paragraph vremen3 Shell Programming and Scripting 1 06-11-2015 04:23 PM
Align with printf or other method yanglei_fage Shell Programming and Scripting 7 08-27-2014 05:11 PM
Align or move paragraph right lostincashe Shell Programming and Scripting 18 03-22-2012 08:11 PM
Align the words Lucky123 Shell Programming and Scripting 5 11-29-2011 11:27 PM
Remove interspersed headers in .dat file with AWK gd9629 Shell Programming and Scripting 4 08-10-2011 11:30 AM
How to pull info under headers in file(awk,grep,while loop) kieranfoley Shell Programming and Scripting 2 01-04-2010 07:26 PM
Merging of files with different headers to make combined headers file marut_ashu Shell Programming and Scripting 1 08-07-2009 05:10 AM
To Align clinical data files using awk chowdhut Shell Programming and Scripting 4 06-18-2009 05:07 PM
Remove text between headers while leaving headers intact Trones Shell Programming and Scripting 3 12-27-2008 08:06 PM
Align Text from a file. earlepps UNIX for Dummies Questions & Answers 9 08-01-2006 09:37 AM