I have an output file that is created with a Perl script that I want to align the data into readable columns. The part of my script that does this is below:
printf OUT "%s %s %s %s\n", $tag, $repo, $message, $developer;
I have 10 spaces in between each column of data, and the output looks like this:
Tag_CYY_20040511_1615 /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
SATURN_20040511_B_BRYAN /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
SATURN_20040511_A_BRYAN /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
SATURN_20040511_D /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
I want to format the output so all the columns are aligned:
Tag_CYY_20040511_1615 /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
SATURN_20040511_B_BRYAN /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
SATURN_20040511_A_BRYAN /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
SATURN_20040511_D /home/cvs/eng/Sonata2/dev/
clasi/incl
ude Bugzilla #18291 chouston
I know you can do this with printf or sprintf, but what kind of syntax should I use? And also, how can I guarantee that the columns will always be aligned, no matter how long each field of data might be? Thanks!
Start Free Trial