Arrange Data in table and send by mail

Everybody,

can you tell me how express about this; we have text data file as :

parameter1 Parameter2
AA 55
BB 77
. .
. .
. .

We want to draw table for this data as attached then send as body of Email

$
$ cat -n f5
     1  Parameter1 Parameter2
     2  AA 55
     3  BB 77
$
$ cat -n f5.pl
     1  #!/usr/bin/perl -w
     2  open(IN, "f5") or die "Can't open f5: $!";
     3  printf("%s\n","-"x31);
     4  while(<IN>) {
     5    chomp;
     6    ($t1,$t2) = split;
     7    if ($. == 1) {
     8      $fmt = "|  %10s  |  %10s  |\n".("-"x31)."\n";
     9    } else {
    10      $fmt = "|  %10s  |  %10d  |\n".("-"x31)."\n";
    11      $sum += $t2;
    12    }
    13    printf($fmt,$t1,$t2);
    14  }
    15  printf("|       Total = %3d           |\n",$sum);
    16  printf("%s\n","-"x31);
    17  close(IN) or die "Can't close f5: $!";
    18
$
$ perl f5.pl
-------------------------------
|  Parameter1  |  Parameter2  |
-------------------------------
|          AA  |          55  |
-------------------------------
|          BB  |          77  |
-------------------------------
|       Total = 132           |
-------------------------------
$
$

tyler_durden

Troffngroffyawk: :wink:

awk 'BEGIN {printf ".TS\nallbox;\nc c\nc c.\n" ; OFS="\t"}
           {t+=$2 ; print $1,$2}
     END  {print "Total",t;print ".TE"}' infile |
     groff -t -T ascii 2>&-

output

+-----------+------------+
|Parameter1 | Parameter2 |
+-----------+------------+
|    AA     |     55     |
+-----------+------------+
|    BB     |     77     |
+-----------+------------+
|  Total    |    132     |
+-----------+------------+

Thx all, but if in case the Parameter1 and Parameter2 not include in this text file, how we insert it in the table when we build it using AWK.

E.g.:

echo "Parameter1 Parameter2" | cat - infile |
awk 'BEGIN {printf ".TS\nallbox;\nc c\nc c.\n" ; OFS="\t"}
           {t+=$2 ; print $1,$2}
     END  {print "Total",t;print ".TE"}' |
groff -t -T ascii 2>&-

-or-

awk 'BEGIN {printf ".TS\nallbox;\nc c\nc c.\n" ; OFS="\t"}
           {t+=$2 ; print $1,$2}
     END  {print "Total",t;print ".TE"}' <( echo "Parameter1 Parameter2" | cat - infile ) |
     groff -t -T ascii 2>&-