Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to access DbaseIII (dbf) from batch?

103 views
Skip to first unread message

Leary

unread,
May 3, 2001, 9:20:50 PM5/3/01
to
I need to get at some data stored in a dbase file. Is this possible?

Phil Robyn

unread,
May 3, 2001, 11:50:49 PM5/3/01
to
Leary wrote:

> I need to get at some data stored in a dbase file. Is this possible?

Might be. First, just look at the file with a text editor and see if you
can figure out where the header information ends and the data begins.
A lot depends on how long the records in the data portion are and
whether there are any 'poison' characters (<>|^&). I have done
this years ago (but NOT with batch!), and I remember that it was
a real hassle. Unfortunately, I don't have any .dbf files to play with,
so I can't be more helpful. Good luck, and let us know how it goes.


Matt Connew

unread,
May 4, 2001, 4:34:13 AM5/4/01
to
Try looking at http://www.wotsit.org/ or more specifically
http://www.wotsit.org/download.asp?f=dbf .
This is the file format description of DBase files. Really useful site.

Matt

"Leary" <le...@foad.NOSPAM.org> wrote in message
news:RqnI6.11314$c4.6...@e420r-chi1.usenetserver.com...

Jim Lawless

unread,
May 4, 2001, 7:33:39 AM5/4/01
to
In article <RqnI6.11314$c4.6...@e420r-chi1.usenetserver.com>,
le...@foad.NOSPAM.org says...

>
>I need to get at some data stored in a dbase file. Is this possible?

Short of finding a utility to dump a dbase file, you might want
to set up an ODBC data-source to point to the file ( using a dbase
or FoxPro driver. )

Then, you could use the Windows Scripting Host to read the file
via the ODBC reference.

A simpler way might be to import the file into another tool
( such as a spreadsheet ), then export it to a pure text file.

Jim Lawless * ji...@radiks.net * http://www.radiks.net/~jimbo
http://www.mailsend-online.com * Command-line e-mail tools,
tiny scheduler, DUN hangup, batch script language

terry.hollis

unread,
May 4, 2001, 8:06:29 AM5/4/01
to
"Leary" <le...@foad.NOSPAM.org> wrote in message
news:RqnI6.11314$c4.6...@e420r-chi1.usenetserver.com...
> I need to get at some data stored in a dbase file. Is this possible?

I assume that you do not have a copy of the dBASE programs.

You can open dBASE data files with most spreadsheets and database programs
such as MSWorks.

--
Regards - Terry Hollis

Leary

unread,
May 4, 2001, 8:41:16 AM5/4/01
to

"terry.hollis" <terry....@xtra.co.nz> wrote in message
news:fXwI6.1238$1i5.1...@news.xtra.co.nz...

I can get at it by importing to excel then saving as csv. There is the issue
of the empty fields that was addressed in an earlier post (news server
completely reset last night so I can't get the specific message reference
right now). I'm working on a way to get at the data thru straight script
because thats all I can count on being available on the servers where the
script would run. To make a long story short I'm parsing log files that have
ID#'s in them referencing fields (name) in dbf files. Actually having just
the ID#'s on the reports will fit the bill... it just seemed like a good
method of learning to go the extra mile to add the name on the reports.
I'll check out some of the links provided and followup later.

ma...@nospam.optusnet.com.au

unread,
May 4, 2001, 8:40:24 AM5/4/01
to
I use cdbflite (Shareware $15.00). Command line access to query, add,
delete etc.

Check it out at: http://www.whitetown.com/cdbflite/index.html

Michael


"Leary" <le...@foad.NOSPAM.org> wrote in <RqnI6.11314$c4.694849@e420r-
chi1.usenetserver.com>:

Joe User

unread,
May 4, 2001, 10:29:15 AM5/4/01
to
Here's my post from last night, re opening up the consecutive
delimiters in a CSV type of file...


001: @echo off
002: if "%1"=="" echo usage: fixcdf infile [^> outfile] & goto:eof
003: setlocal
004: for /f "tokens=*" %%f in (%~s1) do call :change %%f
005: goto:eof
006: :change
007: set line=%*
008: if "%line:~0,1%"=="," set line= %line%
009: set line=%line:,,=, ,%
010: set line=%line:,,=, ,%
011: echo %line%
012: goto:eof

It checks for an empty first field and then proceeds to open up
consecutive commas further along each record. Lines 9 and 10 are
intentionally duplicated since string replacement is not recursive and
two hits are needed to cover ",,," or ",,,,,," or whatever.

Enjoy!
Brad Berson
brad dot berson at rectaltronics dot com

On Fri, 4 May 2001 07:41:16 -0500, "Leary" <le...@foad.NOSPAM.org>
wrote:

Leary

unread,
May 4, 2001, 7:07:25 PM5/4/01
to
OK this looks promising... now could someone refer me to info on dealing
with a | in data? Unless Mike can tell me how to get it out from CDBFLITE
without the |.

Leary

unread,
May 4, 2001, 7:36:02 PM5/4/01
to
Here's what I'm doing now.. which does work.. seems as though there must be
a more elegant solution..
I'm getting the data from the dbf as seperate cmds avoid having to deal with
the | at the end of the fields. Seems to not even slow down things much.

:ACCTNAME
set ACCT=%1
set ncnt=1
cdbflite data\hse.dbf /filter:id=%ACCT% /select:firstname>ACCTNAME.txt
cdbflite data\hse.dbf /filter:id=%ACCT% /select:lastname>>ACCTNAME.txt
for /f "tokens=1" %%G in (ACCTNAME.txt) do (
call:PARSENAME %%G
)
goto:eof

:PARSENAME
if "%ncnt%"=="1" set FIRSTNAME=%1
if "%ncnt%"=="2" set LASTNAME=%1
set /a ncnt+=1
goto:eof

"Leary" wrote in message:

Michael Jerkovic

unread,
May 5, 2001, 8:03:06 AM5/5/01
to
Leary

its all coming back to me. I had the same problem with the | characters.
It is a real pity cdbflite doesn't allow another delimiter.

I've gone back to the scripts I wrote and noticed that I was actaully using
two utilities, cdbflite and convert.exe. Convert.exe is also freeware, a
16 bit program by Bruce Guthrie. It can convert dbf's to comma delimited
txt files. See http://users.erols.com/waynesof/bruce.htm.

If my memory servers me correctly, convert.exe also allows filtering, but I
ended using cdblite as a preprocessor for reasons I now can't remember. It
may have been speed as my source dbase file was about 400Mb. Using
cdbflite I created a new dbase file that only created the data I needed,
and I then used convert to move this into a comman delimited text file.

The code looked someting like:

1. cdbflite BIG.DBF /filter:NAME=Joe /order:NAME;CITY /hdr+ /trim:all
/out:small.dbf /select:NAME;CITY;EMAIL
2. convert small.dbf /from dbf /to ascii /delims=,,, /header

Note that I was usinfg older versions of both cdflite and convert, so I
cant guarentee the above is 100% syntatically correct.

Your batch solution is quite nice. If you are querying small dbase files
you may want to stick to it. You could also try using just convert.exe.
I apologise for only giving you half the story the first time around.

Michael


"Leary" <le...@foad.NOSPAM.org> wrote in
<p_GI6.1001$g61....@e420r-chi1.usenetserver.com>:

>Here's what I'm doing now.. which does work.. seems as though there must
>be a more elegant solution..
>I'm getting the data from the dbf as seperate cmds avoid having to deal
>with the | at the end of the fields. Seems to not even slow down things
>much.
>
>:ACCTNAME
>set ACCT=%1
>set ncnt=1
>cdbflite data\hse.dbf /filter:id=%ACCT% /select:firstname>ACCTNAME.txt
>cdbflite data\hse.dbf /filter:id=%ACCT% /select:lastname>>ACCTNAME.txt
>for /f "tokens=1" %%G in (ACCTNAME.txt) do (
> call:PARSENAME %%G
>)
>goto:eof
>
>:PARSENAME
>if "%ncnt%"=="1" set FIRSTNAME=%1
>if "%ncnt%"=="2" set LASTNAME=%1
>set /a ncnt+=1
>goto:eof
>

>> OK this looks promising... now could someone refer me to info on
>> dealing with a | in data? Unless Mike can tell me how to get it out
>> from CDBFLITE without the |.
>>
>> > I use cdbflite (Shareware $15.00). Command line access to query,
>> > add, delete etc.
>> >
>> > Check it out at: http://www.whitetown.com/cdbflite/index.html
>> >

Leary

unread,
May 7, 2001, 12:19:20 AM5/7/01
to
CDBFLite did the trick quite nicely. Turns out it works great to use a pipe
and a space as delims.

Thanx

"Michael Jerkovic" wrote in message

0 new messages