![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to align report headers in awk
Is it any way exept playing with spaces (tabs don't help)
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|||
|
|||
|
how to align headers
I only see tabs in printf command and it doesn't help. Can somebody give me an example?
|
|
#4
|
||||
|
||||
|
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")
}
}
|
||||
| Google The UNIX and Linux Forums |