[ale] center justification in column using awk or perl

Dow Hurst dhurst at kennesaw.edu
Tue Jun 18 13:04:42 EDT 2002


I need to center justify a column either using awk or perl.  I 
understand the awk printf command  at the command line and don't see a 
way to use it to do this.  I am looking at the format/write statements 
in Perl, which will do what I want.  Here is the code I have to work 
with in Perl currently that needs to be transformed from a printf to a 
format/write.

for ( $i = 0; $i <= $#AtomType; $i++ ) {

    printf CLSTout "%4d %5d %d %5d %d %5d %d %5d %d %5d %d %5d %d %11.6f 
%11.6f %11.6f %7s%4d%9.5f%9.5f %4s %4s\n", $AtomType[$i], 
$$connect[$i][0], $$bonding[$i][0],$$connect[$i][1], $$bonding[$i][1], 
$$connect[$i][2], $$bonding[$i][2], $Connect7[$i], $Connect8[$i], 
$Connect9[$i], $Connect10[$i], $Connect11[$i], $Connect12[$i], 
$Xcoord[$i], $Ycoord[$i], $Zcoord[$i], $Thing[$i], $AtomColor[$i], 
$Charge1[$i], $Charge2[$i], $ResName[$i], $AtomName[$i];

}
close(CLST);
close(CLSTout);


All I want to do is center justify the last column in the printf 
statement.   Thanks for the help!  I am working on the format statement 
but don't really know how to set it up.  I know I should use a "@||||" 
for the last column in the format statement but then I don't know how to 
setup up the decimal places in the columns that need them.
Dow



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list