Question: I'm trying to generate a summary report in bash. My text file format's this way:

```
title:composer:price:musical pieces available:musical pieces sold

```

However, in my report output's supposed to be this way :

```
Title       Composer   Price   PiecesAvail   PiecesSold   TotalProfit
Graham      Jack       20.00       10            2           40.00
Zack        Squall      4.00       5             3            7.00

```

Anyone can point me in the right direction? I would have to either calculate the total profit beforehand,or while generating the report.

A sample of the textfile's here:

```
 Graham:Jack:20.00:10:2
 Jack:Squall:4.00:5:3
 Random - One:Jim:5.00:4:1
 RainyDay:Melissa:50.00:2:1

```

I've not thought how to calculate the total profit yet though.

Answer: 
Perl to the rescue, using [Text::Table](http://p3rl.org/Text::Table):

```
#!/usr/bin/perl
use warnings;
use strict;

use Text::Table;

my $t = 'Text::Table'->new('Title',
                           'Composer',
                           'Price',
                           'Pieces Available',
                           'Pieces Sold',
                           'Total Profit',
                          );
while (<>) {
    my ($title, $composer, $price, $available, $sold) = split /:/;
    my $profit = sprintf '%.2f', $price * $sold;
    $t->add($title, $composer, $price, $available, $sold, $profit);
}

print $t;

```
```
awk -F':' '
BEGIN {
    fmt = "%-15s%-11s%5s   %11s   %10s   %11s\n"
    printf fmt, "Title","Composer","Price","PiecesAvail","PiecesSold","TotalProfit"
}
{ printf fmt, $1,$2,$3,$4"     ",$5"     ",sprintf("%.2f   ",$3*$5) }
' file
Title          Composer   Price   PiecesAvail   PiecesSold   TotalProfit
Graham         Jack       20.00       10            2           40.00    
Jack           Squall      4.00        5            3           12.00    
Random - One   Jim         5.00        4            1            5.00    
RainyDay       Melissa    50.00        2            1           50.00  

```