DBF viewer for Ubuntu

According to the LibreOffice Wiki you should be able to open .dbf files with LibreOffice Base.

If you still encounter this problem, reinstall LibreOffice:

sudo apt-get remove --purge libreoffice*
sudo apt-get clean
sudo apt-get autoremove
sudo apt-get install libreoffice

You can also use dbview to open .dbf files (which may be harder to use than LibreOffice Base):

sudo apt-get install dbview

Refer to the manpage for more information on dbview.


For very simple editing of small .dbf files, you can also use GTK DBF Editor

To install it in Ubuntu 12.04, I first needed to install this dependency:

sudo apt-get install libglade2-0:i386

Then I could install the downloaded .deb file with

sudo dpkg -i Downloads/gtkdbfeditor_1.0.4-7_i386.deb

Update:

In Ubuntu 16.04, with the default install of LibreOffice, I had to also

sudo apt install libreoffice-base

Then, .dbf files can be opened in LibreOffice Calc, and also saved as .dbf.


I have found the best way to deal with .dbf files is to use PHP to convert them to .csv files:

<?php

set_time_limit( 24192000 );
ini_set( 'memory_limit', '-1' );

$files = glob( '/media/d/Data2/files/*.DBF' );
foreach( $files as $file )
{
    echo "Processing: $file\n";
    $fileParts = explode( '/', $file );
    $endPart = $fileParts[key( array_slice( $fileParts, -1, 1, true ) )];
    $csvFile = preg_replace( '~\.[a-z]+$~i', '.csv', $endPart );

    if( !$dbf = dbase_open( $file, 0 ) ) die( "Could not connect to: $file" );
    $num_rec = dbase_numrecords( $dbf );
    $num_fields = dbase_numfields( $dbf );

    $fields = array();
    $out = '';

    for( $i = 1; $i <= $num_rec; $i++ )
    {
        $row = @dbase_get_record_with_names( $dbf, $i );
        $firstKey = key( array_slice( $row, 0, 1, true ) );
        foreach( $row as $key => $val )
        {
            if( $key == 'deleted' ) continue;
            if( $firstKey != $key ) $out .= ';';
            $out .= trim( $val );
        }
        $out .= "\n";
    }

    file_put_contents( $csvFile, $out );
}

?>

Then use MySQL to import the CSV:

LOAD DATA INFILE "/media/d/Data2/files/ZACATECAS.csv" INTO TABLE tbl FIELDS TERMINATED BY ";" ENCLOSED BY '"' LINES TERMINATED BY "\n";