Gossamer Forum
Home : Products : DBMan : Customization :

External Text File Mod

Quote Reply
External Text File Mod
The mod itself is clear to me, that is to say I have not implemented it yet.

I want to implement it on an exitsting dbman database which is around 1 MB big. It contains 1,200 records.

I ain't looking foreward to manually changing 1,200 records and adding 1,200 .txt files.

Is there a way to automate it? (through excel/access?) I am able to put it in access but have no idea on how to export all those field to 1,200 individual .txt files

Anybody any tips or other ways how to archieve this?

Close Watch
LyricZ http://www.lyricz.12inter.net
NL
Quote Reply
Re: External Text File Mod In reply to
you can write a small perl script to do the job.
just define how you would name that files...
the script is quite simple :

read your db
for each line split values
put the wanted value in a file

that's all...
my ($line, @data, $field);
$db_file_name = "FULL PATH TO YOUR DB";
$outdir = "DIRECTORY TO PUT FILES WITH TRAILING SLASH";
open (DB, $db_file_name);
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
# Assuming you want call your files as ID.txt where ID is in field 0
$outfile = @data[0].".txt";
open (OUT, ">$outdir/$outfile");
# Assuming data you want to export are in field 3
print OUT @data[3];
close OUT;
}
close DB;
exit;

sub split_decode
{
my ($input) = shift;
$input =~ s/\Q|\E$/$db_delim /o;
my (@array) = split (/\Q|\E/o, $input);
for ($i = 0; $i <= $#array; $i++)
{
$array[$i] =~ s/~~/|/og;
$array[$i] =~ s/`/\n/g;
return @array;
}
}

........................

i tried it...it works...

Valerio [Hypo] Verde

Quote Reply
Re: External Text File Mod In reply to
Thanx !

Works like a breeze.

Close Watch
LyricZ http://www.lyricz.12inter.net
NL
Quote Reply
Re: External Text File Mod In reply to
new records display allright (line breaks etc)

The records which are converted dont show line breaks
$rec{'text'} =~ s/\n/<BR>/g;
doesnt work on 'old records'.

What can I do?

Close Watch
LyricZ http://www.lyricz.12inter.net
NL
Quote Reply
Re: External Text File Mod In reply to
I'm not really understand on what kind of data wont work...

will you write 2 or 3 (before converting) lines ???

so i could understand why...

(i tried converting data with <BR> and \n inside...)and it works...

[Hypo]

Quote Reply
Re: External Text File Mod In reply to
I am not sure what you are saying...
But the converted text files contain '' as line breakes.
When returned the '' are just as they are and aint converted to line breaks as happens when a new record is added.

Close Watch
LyricZ http://www.lyricz.12inter.net
NL
Quote Reply
Re: External Text File Mod In reply to
Sorry...my fault...( i lost 30 minutes to figure out what was the problem...and the answer was under my eyes :P )

Windows 2k seems to strip some char out when pasting...

the code is THIS :

my ($line, @data, $field);
$db_file_name = "c:/cgi-bin/dbman/default.db";
$outdir = "c:/cgi-bin/dbman/auth/";
open (DB, $db_file_name);
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
# Assuming you want call your files as ID.txt where ID is in field 0
$outfile = @data[0].".txt";
open (OUT, ">$outdir/$outfile");
# Assuming data you want to export are in field 3
print OUT @data[6];
close OUT;
}
close DB;
exit;


sub split_decode
{
my ($input) = shift;
$input =~ s/\Q|\E$/| /o;
my (@array) = split (/\Q|\E/o, $input);
for ($i = 0; $i <= $#array; $i++)
{
$array[$i] =~ s/~~/|/og;
$array[$i] =~ s/``/\n/g;
}
return @array;
}
-----------------------------
Let me know :=)

Valerio [Hypo] Verde

Quote Reply
Re: External Text File Mod In reply to
thank you for all your time and work !

Close Watch
LyricZ http://www.lyricz.12inter.net
NL