Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Exporting links

Quote Reply
Exporting links
I have seen several posts about importing into Links but I would like to export my links.db to a CSV file. But, I only want 3 fields exported: Site name, description, URL.

How can I do this? Anyone have a script that can do this? I don't want to manually go through my 150+ entries manually to do this.

Jorge

www.diecast-source.com
Quote Reply
Re: Exporting links In reply to
um.. links.db is a CSV file. Anyway, if you want to export certain fields into another file, then you'd do something like:
Code:
#!/usr/local/bin/perl
require "/home/yoursite/www/cgi-bin/links/admin/links.cfg";
require "$db_lib_path/links.def";
my @fields = qw(1 2 3); #field (positions) to export
my $delim = "|"; #output field seperator
open (IN, "$db_links_name") or die $!;
open (OUT, ">$db_links_name.csv") or die $!;
while (<IN>) {
chomp;
my @values = split /\|/;
my $first = pop @fields;
print OUT $first;
if (scalar @fields) {
foreach my $field (@fields) {
print OUT $delim, $values[$field];
}
}
print OUT "\n";
}
close OUT;
clos IN;
print "Content-type: text/html\n\n";
print qq|Your file has been exported to $db_links_name.csv.|;
Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: Exporting links In reply to
I tried the script but it doesn't seem to export anything past my second record. The script runs and says it exported my links.db but when I open the CSV file there are only 2 entries.

Also, you left an "e" off the last "close"

Thanks for the script.

Jorge

www.diecast-source.com
Quote Reply
Re: Exporting links In reply to
I don't know what to tell ya :-) I don't make guarantee's on 3 minute scripts. If I find some time this week I'll take a look at it.

Happy coding,

--Drew
http://www.camelsoup.com
ftp://ftp.camelsoup.com
Quote Reply
Re: Exporting links In reply to
Use AWK. It's the exact solution to your problem.
If your OS is Unix, you already have it.
If Windows, search Google on 'awk for Windows' or go straight to http://www.crossmyt.com/...mlchek/awk-perl.html -- you will definitely find it.

Easy to use, eg: if you wanted to print fields 1, 4 and 7 separated by a pipe, into a file named subset.db, enter
awk -F\| '{print $1 "|" $4 "|" $7}' links.db > subset.db