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: 
see if this is what you need:

```
kent$  awk -F':' -v OFS="\t" 'BEGIN{print "Title","Composer", "Price", "PA","PS","TotalP"}{"$1=$1";$(NF+1)=$3*$NF}7' f|column -t -s'    '
Title         Composer  Price  PA  PS  TotalP
Graham        Jack      20.00  10  2   40
Jack          Squall    4.00   5   3   12
Random - One  Jim       5.00   4   1   5
RainyDay      Melissa   50.00  2   1   50

```

* I've shorten the words in header, you can put the full words there
* the last `' '` is `ctrl-v tab`
* the total Profit I just did as `Price * PieceSold`
Pretty-printing columns can be fiddly, especially if the maximum length of each field is not known in advance. You can use `printf` in awk to do a reasonable enough job though:

```
awk -F: 'BEGIN { printf "%12s%12s%8s%12s%12s\n", "Title","Composer","Price","PiecesAvail","PiecesSold"
}
{ printf "%12s%12s%8s%12s%12s\n",$1,$2,$3,$4,$5 }' file

```

I've specified the colon as the field separator using the switch `-F:`.

The `BEGIN` block prints the headers and every other line is printed using the same format. The format `%Ns` specifies a string padded to `N` characters, so it can be used for fixed width output.

I didn't calculate your total profit but that could be added in as an extra column. If for example it was as simple as `Price * PiecesSolid`, that would be `$3*$5` (column 3 multiplied by column 5). To show it as a number with two decimal places, you could add `%.2f` to the end of the `printf` statement.