Hi,
I have one file as follows and I need to read this file contents in an HTML format. And send html file to some mail ids using sendmail.
Communications Pvt Ltd
Report
AccountId Name Code IdBill Balance Amount
----------- ----- ------ ---- ------- -------
123123 aaaa 11 12 1000.00 1111.00
-- -- -- -- -- --
TOTAL : 1111
Can anybody help me out?
What do you mean by html format?
you could simply add a pre tag around it... or do want to build a full table structure ?
You have provided your input - is this exactly the same for all inputs, or will you have multiple rows etc ?
What is your expected/preferred output?
And....What have you tried so far? Post your attempts and you will get feedback and assistance...
I'd go from the opposite direction. I'd start with an html template that has the (outer elements of the) table pre-written.
Then, I'd use perl or PHP to scrape the text file and drop the listed values into rows. That works out to a file read and a loop, and all the hard work is done before you run the script.
You might find following Perl script useful... Feel free to tweak it for your needs.
#!/usr/local/bin/perl
use strict;
use warnings;
my $acc=0;
my $tot=0;
my @dsplit;
my $infile='input.dat';
my $outfile='input.html';
open(I,$infile) or die "Error opening input file: $!\n";
my @data=<I>;
close(I);
open(O,">$outfile") or die "Error opening output file: $!\n";
print O "<table>\n";
foreach my $line (@data) {
chomp($line);
if ($line =~ /^Acc/) {
$acc=1;
}
if ($line =~ /^TOT/) {
$tot=1;
}
if ($acc == 0) {
print O "<tr><center>$line</center></tr>\n";
}
elsif ($acc == 1 && $tot == 0) {
$line =~ s/ */ /g;
@dsplit=split(/ /,$line);
print O "<tr>";
foreach my $record (@dsplit) {
chomp($record);
print O "<td>$record</td>";
}
print O "</tr>\n";
}
else {
@dsplit=split(/ /,$line);
print O "<tr><td>TOTAL:</td><td></td><td></td><td></td><td></td><td>$dsplit[-1]</td></tr>\n";
}
}
print O "</table>";
close(O);
$ cat input.dat
Communications Pvt Ltd
Report
AccountId Name Code IdBill Balance Amount
----------- ----- ------ ---- ------- -------
123123 aaaa 11 12 1000.00 1111.00
232423 abbb 21 12 1000.00 9999.00
156763 acdf 11 12 1000.00 1111.00
145633 aasw 31 12 3333.00 7777.00
235453 wwww 11 12 1000.00 1111.00
232343 asss 31 12 1000.00 1111.00
332423 eeEa 11 12 1222.00 7777.00
253123 aaaa 12 12 1000.00 1111.00
253123 adfd 11 12 1000.00 4444.00
125443 aAda 10 12 2434.00 1111.00
662123 hgja 11 12 1000.00 1000.00
TOTAL : xxxxxx
$
$ ./putintable.pl
$
$ cat input.html
<table>
<tr><center> Communications Pvt Ltd</center></tr>
<tr><center> Report</center></tr>
<tr><center></center></tr>
<tr><td>AccountId</td><td>Name</td><td>Code</td><td>IdBill</td><td>Balance</td><td>Amount</td></tr>
<tr><td>-----------</td><td>-----</td><td>------</td><td>----</td><td>-------</td><td>-------</td></tr>
<tr><td>123123</td><td>aaaa</td><td>11</td><td>12</td><td>1000.00</td><td>1111.00</td></tr>
<tr><td>232423</td><td>abbb</td><td>21</td><td>12</td><td>1000.00</td><td>9999.00</td></tr>
<tr><td>156763</td><td>acdf</td><td>11</td><td>12</td><td>1000.00</td><td>1111.00</td></tr>
<tr><td>145633</td><td>aasw</td><td>31</td><td>12</td><td>3333.00</td><td>7777.00</td></tr>
<tr><td>235453</td><td>wwww</td><td>11</td><td>12</td><td>1000.00</td><td>1111.00</td></tr>
<tr><td>232343</td><td>asss</td><td>31</td><td>12</td><td>1000.00</td><td>1111.00</td></tr>
<tr><td>332423</td><td>eeEa</td><td>11</td><td>12</td><td>1222.00</td><td>7777.00</td></tr>
<tr><td>253123</td><td>aaaa</td><td>12</td><td>12</td><td>1000.00</td><td>1111.00</td></tr>
<tr><td>253123</td><td>adfd</td><td>11</td><td>12</td><td>1000.00</td><td>4444.00</td></tr>
<tr><td>125443</td><td>aAda</td><td>10</td><td>12</td><td>2434.00</td><td>1111.00</td></tr>
<tr><td>662123</td><td>hgja</td><td>11</td><td>12</td><td>1000.00</td><td>1000.00</td></tr>
<tr></tr>
<tr><td>TOTAL:</td><td></td><td></td><td></td><td></td><td>xxxxxx</td></tr>
</table>$