Dbf to csv linux

Содержание
  1. Export DBF to CSV
  2. Export DBF to CSV from the command line:
  3. Simple export dbf to csv
  4. Export DBF to CSV with double quotes
  5. Export dbf to csv with semicolon as delimiter
  6. Export DBF to CSV with Pipe as delimiter
  7. Export DBF to CSV with columns selection
  8. Exporting with filter
  9. GIS-LAB
  10. Конвертация DBF в CSV
  11. [править] Использование
  12. [править] Примеры
  13. [править] Ссылки по теме
  14. Convert DBF to CSV on Linux with Perl and XBase
  15. 9 thoughts on “ Convert DBF to CSV on Linux with Perl and XBase ”
  16. Leave a Reply Cancel reply
  17. About Avi
  18. bertspaan / README.md
  19. This comment has been minimized.
  20. bertspaan commented Jan 2, 2014
  21. This comment has been minimized.
  22. Stavrakoss commented Mar 26, 2015
  23. This comment has been minimized.
  24. 0t3dWCE commented Jul 27, 2015
  25. This comment has been minimized.
  26. jhli973 commented Feb 24, 2016
  27. This comment has been minimized.
  28. rilarios commented Mar 3, 2016
  29. This comment has been minimized.
  30. riordan commented May 1, 2016
  31. This comment has been minimized.
  32. santu1987 commented May 10, 2016
  33. This comment has been minimized.
  34. mruepp commented May 19, 2016
  35. This comment has been minimized.
  36. bolatov commented May 26, 2016 •
  37. This comment has been minimized.
  38. celisflen-bers commented Sep 24, 2016
  39. This comment has been minimized.
  40. Felipe3000W commented Nov 17, 2016
  41. This comment has been minimized.
  42. gtdca98 commented Jan 6, 2017
  43. This comment has been minimized.
  44. rolando-urrea commented Jun 2, 2017
  45. This comment has been minimized.
  46. Cyberguille commented Jul 13, 2017
  47. This comment has been minimized.
  48. rpsingh21 commented Aug 4, 2017
  49. This comment has been minimized.
  50. martinmanzo commented Oct 9, 2017
  51. This comment has been minimized.
  52. tvequaud commented Oct 20, 2017
  53. This comment has been minimized.
  54. agustinramos commented Oct 27, 2017 •
  55. This comment has been minimized.
  56. AlJohri commented Oct 29, 2017 •
  57. This comment has been minimized.
  58. mateice commented Nov 30, 2017

Export DBF to CSV

To export a dbf file to CSV format, open File | Save as/Export menu, and select file type: CSV.

Export to dialog box opens. Select the fields to be exported and specify their order using up and down arrows.

You can select also field delimiter: comma, semicolon, tab, space or enter other delimiter.

Export DBF to CSV from the command line:

«c:\Program Files\DBF Viewer 2000\dbview.exe» file.dbf /EXPORT:file.csv [/SEPx |/SEPTAB |/SEPSPACE | /SEPPIPE | /SINGLEQUOTA | /DOUBLEQUOTA | /REVERSE | /STARTFROM | /FILTER | /SORTBY:field | /UTF8]

Simple export dbf to csv

«c:\Program Files\DBF Viewer 2000\dbview.exe» sample.dbf /EXPORT:sample.csv

Export DBF to CSV with double quotes

«c:\Program Files\DBF Viewer 2000\dbview.exe» sample.dbf /EXPORT:sample.csv /DOUBLEQUOTA

Export dbf to csv with semicolon as delimiter

«c:\Program Files\DBF Viewer 2000\dbview.exe» sample.dbf /EXPORT:sample.csv /SEP;

Export DBF to CSV with Pipe as delimiter

«c:\Program Files\DBF Viewer 2000\dbview.exe» sample.dbf /EXPORT:sample.csv /SEPPIPE

Export DBF to CSV with columns selection

«c:\Program Files\DBF Viewer 2000\dbview.exe» sample.dbf /EXPORT:sample.csv /COLUMNS:ZIP,NAME

Exporting with filter

«c:\Program Files\DBF Viewer 2000\dbview.exe» sample.dbf /EXPORT:sample.csv /FILTER:filter.txt

Syntatx for filter file (each line):
Fieldname:Value|Expresion

Источник

GIS-LAB

Географические информационные системы и дистанционное зондирование

Конвертация DBF в CSV

При работе с shape-файлами и не только довольно часто встречается задача преобразования файла формата dbf в обычный текстовый файл с разделителями. И хотя програм, производящих такого рода преобразование, достаточно много (например, широко распространенные MSOffice или OOffice), во многих случаях бывает удобно использовать небольшую специализированную утилиту, вызываемую из командной строки.

Для преобразования dbfcsv можно использовать скрипт на языке Python (скачать скрипт).

Скрипт использует библиотеку dbfpy, которая должна быть установлена в системе (скачать dbf2py).

Читайте также:  Mysql mac os big sur

[править] Использование

Утилита вызывается из командной строки и принимает несколько параметров:

  • DBFfile — обязательный параметр: имя файла dbf, который требуется преобразовать в файл csv
  • CSVfile — необязательный параметр: имя файла csv, в который будет записано содержимое файла dbf. Если данный параметр не указан, содержимое dbf-файла будет отправлено на стандартый вывод (stdout).
  • header — необязательный параметр, может принимать два значения: True (записывать в файл заголовки полей) или False (не писать заголовки полей). По умолчанию он равен True
  • delim — необязательный параметр: указвает строку-разделитель полей в результирующем файле csv. По умолчанию равен запятой («,»).
  • cols — порядковые номера импортируемых полей (первое поле имеет номер 1).

[править] Примеры

Импортировать все в файл data.csv, не добавлять имена полей

Импортировать все в файл text.csv, добавлять имена полей, использовать разделитель «&»

[править] Ссылки по теме

Последнее обновление: 2014-05-14 22:43

Дата создания: 12.12.2009
Автор(ы): Дмитрий Колесов

Источник

Convert DBF to CSV on Linux with Perl and XBase

I spent a few days to figure out how to make a simple conversion of a DBF file into a plain text file as comma separated values (CSV) or tab separated values (TSV) in a batch/command line way. I was almost setting up an OpenOffice.org server because it seamed to be the only packaged solution to read and convert DBFs.

Well, it easier than that. The secret lives in the XBase drivers for Perl Data Base Interface project. To install it on Fedora or Red Hat use this command:

If you use other Linux distributions, you may look for a package with a similar name.

For a simple file conversion, you don’t need to program in Perl because the perl-DBD-XBase package contains a command line tool for that: dbftool.pl. So to convert the mytable.dbf file into a more standard CSV file, do this:

If you want to use TAB instead of a comma to separate fields, while editing the command put the cursor between the double quotes, press Ctrl+V and then press the TAB key on your keyboard. This will fill the double quotes with a real (but invisible) TAB char.

9 thoughts on “ Convert DBF to CSV on Linux with Perl and XBase ”

I have just happened to work on some dbf dbase files too recently, and find out your post is very helpful (I plan to use perl dbi at the beginning). Here are some extra works I have done if you run windows, or other distributions of linux, such as opensuse, debian, ubuntu… hope is helpful for anyone who meet the same problem.

ATTENTION: make sure you use –nomemo switch when you run dbfdump, otherwirse you will get error message (missing dbt).

WINDOWS XP: install activeperl, and then install dbd-xbase package under ppm-shell. then run dbfdump.bat (mine is under c:\perl\site\bin)

dbfdump.bat –fs=:|” –nomemo mydebasefile.dbf

LINUX, install perl-dbd-xbase (suse), libdbd-xbase-perl (debian or ubuntu), and run

dbfdump.bat –fs=:|” –nomemo mydebasefile.dbf

for some version incompatible reason, you may get the error message under linux

prototype mismatch: sub Xbase::Base::O_BINARY () vs none at (eval 4). what I did is find the Fcntl.pm file for perl, and comment out the O_BINARY line, it works. If you need more information, google could help you more.

Commented out O_BINARY as suggested

[mlapier@mushroom]$ dbfdump.pl –fs “,” 20110205dailydat.dbf > 20110205dailydat.csv
Possible attempt to put comments in qw() list at /usr/lib/perl5/Fcntl.pm line 140.
Prototype mismatch: sub XBase::Base::O_BINARY () vs none at (eval 5) line 1.
Constant subroutine O_BINARY redefined at (eval 5) line 1.
[mlapier@mushroom]$

I’m open for suggestions? 😉

Читайте также:  Windows phone emulator что это

I have no idea. I used it only once or twice.

I would guess that your DBF has binary fields which are incompatible with such conversion because CSV is text only.

If so, I would guess you need to use the XBase Perl API instead of using the vanilla dump tool.

Another guess is the encoding of text on your DBF file is incompatible with your environment so the tool is interpreting it as binary.

But again, these are only guesses.

Thanks, I have been wondering for years how to insert data from a .dbf into samba and linux server, this has helped considerably. Next step, using diff to check for changes and then to use sed or gawk to take certain fields from the changes for input into a lazy-admin-tools input file. I might need to use read/readline too.
Learning is fun.

Some work still needs to be done on the intelligent checking of input fields but so far I have tested the following and it worked.
Thanks again to this site, and linuxcommand.org, and man and info pages

Thanks wintel. Used the dbf_dump command from the libdbd-xbase-perl package on Ubuntu to good effect.

Hi. Thank you very much!! it’s helped me alot!

I’m on Ubuntu 14.04 LTS. I installed libdbd-xbase-perl via Synaptic. Then trying to do dbfdump, I got the following:
snoopie2@snoopie2-Compaq-Presario-CQ40-Notebook-PC:

/special-tools/sage-6.2-i686-Linux$ dbfdump
程序“dbfdump”尚未安装。 您可以使用以下命令安装:
sudo apt-get install shapelib
snoopie2@snoopie2-Compaq-Presario-CQ40-Notebook-PC:

/special-tools/sage-6.2-i686-Linux$ sudo apt-get install shapelib[sudo] password for snoopie2:
正在读取软件包列表… 完成
正在分析软件包的依赖关系树
正在读取状态信息… 完成
将会安装下列额外的软件包:
libshp1
下列【新】软件包将被安装:
libshp1 shapelib
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 30 个软件包未被升级。
需要下载 59.2 kB 的软件包。
解压缩后会消耗掉 217 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://hk.archive.ubuntu.com/ubuntu/ trusty/universe libshp1 i386 1.2.10-7 [22.8 kB]
获取:2 http://hk.archive.ubuntu.com/ubuntu/ trusty/universe shapelib i386 1.2.10-7 [36.4 kB]
下载 59.2 kB,耗时 1秒 (40.1 kB/s)
Selecting previously unselected package libshp1:i386.
(正在读取数据库 … 系统当前共安装有 237520 个文件和目录。)
Preparing to unpack …/libshp1_1.2.10-7_i386.deb …
Unpacking libshp1:i386 (1.2.10-7) …
Selecting previously unselected package shapelib.
Preparing to unpack …/shapelib_1.2.10-7_i386.deb …
Unpacking shapelib (1.2.10-7) …
Processing triggers for man-db (2.6.7.1-1) …
正在设置 libshp1:i386 (1.2.10-7) …
正在设置 shapelib (1.2.10-7) …
Processing triggers for libc-bin (2.19-0ubuntu6) …
snoopie2@snoopie2-Compaq-Presario-CQ40-Notebook-PC:

/special-tools/sage-6.2-i686-Linux$ dbfdump
dbfdump [-h] [-r] [-m] xbase_file
-h: Write header info (field descriptions)
-r: Write raw field info, numeric values not reformatted
-m: Multiline, one line per field.
snoopie2@snoopie2-Compaq-Presario-CQ40-Notebook-PC:

/special-tools/sage-6.2-i686-Linux$ man dbfdump
snoopie2@snoopie2-Compaq-Presario-CQ40-Notebook-PC:

/special-tools/sage-6.2-i686-Linux$
It turned out you need to install shapelib to get dbfdump in Ubuntu 14.04.

I installed and used this but the problem I am facing it is that even though the dbf file is converted to csv file it does it without having the header. Meaning the csv file does not have the header that the dbf file was having. How can we resolve this?

Leave a Reply Cancel reply

About Avi

Avi Alkalay is the lead architect for Third Platform solutions (mobile, user engagement, analytics, cloud, security) on the IBM Brazil CAMSS team.

Источник

bertspaan / README.md

Python script to convert DBF database file to CSV

  • First download dbfpy : http://sourceforge.net/projects/dbfpy/files/latest/download?source=files
  • Then install: sudo python setup.py install

To convert DBF file to CSV:

#!/usr/bin/python
import csv
from dbfpy import dbf
import os
import sys
filename = sys . argv [ 1 ]
if filename . endswith ( ‘.dbf’ ):
print «Converting %s to csv» % filename
csv_fn = filename [: — 4 ] + «.csv»
with open ( csv_fn , ‘wb’ ) as csvfile :
in_db = dbf . Dbf ( filename )
out_csv = csv . writer ( csvfile )
names = []
for field in in_db . header . fields :
names . append ( field . name )
out_csv . writerow ( names )
for rec in in_db :
out_csv . writerow ( rec . fieldData )
in_db . close ()
print «Done. «
else :
print «Filename does not end with .dbf»
Читайте также:  Не загружается windows после установки vipnet

This comment has been minimized.

Copy link Quote reply

bertspaan commented Jan 2, 2014

This comment has been minimized.

Copy link Quote reply

Stavrakoss commented Mar 26, 2015

Thanks mate, that’s really handy.

This comment has been minimized.

Copy link Quote reply

0t3dWCE commented Jul 27, 2015

Just that I need. Spasibo, tovarish.

This comment has been minimized.

Copy link Quote reply

jhli973 commented Feb 24, 2016

This comment has been minimized.

Copy link Quote reply

rilarios commented Mar 3, 2016

This is great.. thank you very much!! Gracias!

This comment has been minimized.

Copy link Quote reply

riordan commented May 1, 2016

Of course you wrote this, @bertspaan!

This comment has been minimized.

Copy link Quote reply

santu1987 commented May 10, 2016

Good afternoon, thanks for your code, but i have a doubt,
I have a dbf file of 2gb, your program export this a csv file very good, but i need that this csv has comlums wth character delimiter «;».

This comment has been minimized.

Copy link Quote reply

mruepp commented May 19, 2016

Thank you for the script. Unfortunately, it handles ÄÖÜ and stuff not correct, must be a codepage problem. I guess its in dbfpy.

This comment has been minimized.

Copy link Quote reply

bolatov commented May 26, 2016 •

@bertspaan thank you very much!

@mruepp I think the problem is in the encoding. Try to convert your dbf to csv and then specify the encoding when opening the csv file.

This comment has been minimized.

Copy link Quote reply

celisflen-bers commented Sep 24, 2016

This comment has been minimized.

Copy link Quote reply

Felipe3000W commented Nov 17, 2016

If you want to change the delimiter try this at line 14

out_csv = csv.writer(csvfile,delimiter=’|’)
where «|» would be the delimiter. you can choose «;» «@» ,etc

This comment has been minimized.

Copy link Quote reply

gtdca98 commented Jan 6, 2017

Thanks. Simple and effective

This comment has been minimized.

Copy link Quote reply

rolando-urrea commented Jun 2, 2017

Thanks mate! It was very helpful!

This comment has been minimized.

Copy link Quote reply

Cyberguille commented Jul 13, 2017

I apply this for one file and I got

This comment has been minimized.

Copy link Quote reply

rpsingh21 commented Aug 4, 2017

how to install dbfpy module in virtual env.?

This comment has been minimized.

Copy link Quote reply

martinmanzo commented Oct 9, 2017

@rpsingh21 just pip install dbfpy

This comment has been minimized.

Copy link Quote reply

tvequaud commented Oct 20, 2017

Don’t work with my DBF file.

This comment has been minimized.

Copy link Quote reply

agustinramos commented Oct 27, 2017 •

If you need to filter columns you can use this script
Try this:

This comment has been minimized.

Copy link Quote reply

AlJohri commented Oct 29, 2017 •

This comment has been minimized.

Copy link Quote reply

mateice commented Nov 30, 2017

If you need to filter columns you can use this script
Try this:

Plese tell what to write in the line of

description = ‘Arguments of DBF to CSV converter’
parser = ArgumentParser(description=description)
parser.add_argument(‘-f’, ‘—file’, dest=’file’, required=’true’,
help=»Examples: -i file.dbf»)

parser.add_argument(‘-c’, ‘—colunms’, dest=’colunms’,
type=str, nargs=’*’,
help=»Examples: -c item1 item2 item3″)

I have DBF file with 9500 lines and and A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,,R,S,T,U,W,X,Y,Z,AA,AB. AQ columnes.

And i have to convert the last 130 lines with all columnes
Any idea.
Thank you

Источник

Оцените статью