tags:

views:

432

answers:

3

Hi all,

I have to take a bunch of columnar text files and integrate them into a single big dbf file, possibly with an intermediate step in a sqlite database.

DBF is the basic file of databases, hence the weird request.

Does anybody know a command line tool for going between text and dbf? Or a sqlite way to attach dbf's would work in a pinch.

Tx

A: 

I think this should be migrated to SuperUser, but here is one very good tool, it's called CBDF For Linux

Nathan Campos
+1  A: 

xBase format (aka DBF) is a pretty simple file format, so it shouldn't be hard to work with. Eric Bachman's page on the xBase file format seems to be the most definitive reference I could find.

Somewhere around here I have a Python script called dbf2csv.py that converts a DBF file into a comma-separated text file. The DBF code is based on some Python code I found on the net, I believe from the DBF reader and writer on this page.

Going from text back to DBF might be trickier, because you need to know the data types of each of your table's columns. One simple solution would be to simply store everything as strings. Another solution is to analyze the first N rows and try to guess the type accordingly.

Daniel Pryden
+1  A: 

What I finally hit on was using the PostGIS tools "shp2pgsql" and "pgsql2shp". These convert database tables into and out shapefiles, but if there is no geometry available, they just generate the dbf files. They worked perfectly.

http://postgis.refractions.net/

ws