port to convert comma delimited file
Giorgos Keramidas
keramida at ceid.upatras.gr
Wed Mar 26 03:04:31 PST 2003
On 2003-03-25 20:51, Dru <dlavigne6 at cogeco.ca> wrote:
> I have a comma delimited file with approximately 7000 rows and 5
> columns. I have absolutely no database skills and and almost as
> much HTML skill, yet I need to convert this file into an HTML
> table. Is there something in the ports collection that will do this
> for me, a sort of converter for dummies? Barring that, is there any
> port that will do this, hopefully with docs so I can learn as I go?
Someone mentioned Perl. Try the following little Perl snippet:
#!/usr/bin/perl
print "<TABLE>\n";
while (defined($line = <STDIN>)) {
chomp $line;
print "<TR><TD>" . join("</TD><TD>", split(/;/, $line)) .
"</TD></TR>\n";
}
print "</TABLE>\n";
Save this to a file called csv2html.pl and then run it like this:
$ perl csv2html.pl < filename.csv > filename.html
The power of Unix as an environment comes from the ability to write
small, throw-away programs like this one, in one of the dozens of
scripting languages that are usually available. Why hunt for a port
to do something so simple[1] ?
[1] For some definintion of `simple'.
More information about the freebsd-questions
mailing list