This is a perl script I use to generate sql for insertion
in any sql database from a text file like yours.
It reads text from stdin and puts sql output on stdout
------------
Piet le Roux
-------start script---------------------------
#!/usr/bin/perl -w
die "Usage: $0 tablename datacount skipcount\n" unless @ARGV == 3;
($tablename, $datacount, $skipcount) = @ARGV;
$dcount = 0;
$scount = 0;
@data = ();
while(<STDIN>) {
chop;
if ($dcount < $datacount) {
push @data, $_;
$dcount++;
} elsif ($scount < $skipcount) {
$scount++;
} else {
print "insert into $tablename values(";
$addcomma = 0;
foreach (@data) {
print "," if $addcomma;
$addcomma = 1;
print "\"$_\"";
}
print ");\n";
$dcount = $scount = 0;
@data = ();
}
}
--------end script----------------------
----- Original Message -----
From: Bryan S. Tyson
On Thu, 01 Feb 2001, Bernd wrote:
The structure is like this example:
123.45 Ab123 Abub, Bob All My Favorite Stories
567.89 B45 Banks, Billy Best Loved Chemistry Experiments
Each group of 3 lines would be a record describing a book (call no., author, title).
I typically have 450-500 of these in a file. How can I make this file into a database? (Using Linux tools.)
It is a _database_. :-) You've just described the schema. For what purpose do you want to use the database?
For a person to assign a subject code (e.g. history, art, science) to each book (this would be an additional field) and create reports by subject.
*************************************************** Powered by SuSE Linux 7.0 Professional KMail 1.0.29.2
Bryan S. Tyson bryantyson@earthlink.net ***************************************************
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/support/faq