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

Converting CSV to LDIF

2,995 views
Skip to first unread message

Martin Lönnar

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
Hi,

Is there a script/module to quickly convert CSV files to LDIF files?

/martin lönnar


Aaron Tavistock

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
What is a CSV file?

I've done alot of scripts for converting other formats into LDIF, but I
have no idea what CSV is.


Aaron Tavistock

Craig Berry

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
Aaron Tavistock (aaro...@cs.berkeley.edu) wrote:
: What is a CSV file?

"Comma separated values". Typically, in addition to commas separating
values, values may be double-quoted strings to protect internal commas,
and double quotes inside such strings may be backslashed to protect them.

--
| Craig Berry - cbe...@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "The hills were burning, and the wind was raging; and the
clock struck midnight in the Garden of Allah."

Steve Palincsar

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
CSV stands for "commas separated value" and there
is a perl module in CPAN to help you parse it.

What is LDIF?


Aaron Tavistock wrote:
>
> What is a CSV file?
>

Martin Lönnar

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
LDIF = LDAP Data Interchange Format.

/martin

Martin Lönnar

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
It means "Comma separated values". In my case I guess it should be called
"TSV" for "Tab separated values".

I have a file extraction from an X.500 catalogue wich is a "TSV" file wich
needs to be converted to an LDIF file. How?

/martin

Bart Lateur

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
Craig Berry wrote:

>"Comma separated values". Typically, in addition to commas separating
>values, values may be double-quoted strings to protect internal commas,
>and double quotes inside such strings may be backslashed to protect them.

Ouch. I don't think quotes are backslashed. Otherwise, you'd have to
backslash backslashes too. Quotes are generally *doubled*.

"Hi", she said.
-->
"""Hi"", she said."

Bart.

dragn...@my-dejanews.com

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
In article <36C0A261...@cs.berkeley.edu>,

Aaron Tavistock <aaro...@cs.berkeley.edu> wrote:
> What is a CSV file?
>
> I've done alot of scripts for converting other formats into LDIF, but I
> have no idea what CSV is.
>
> Aaron Tavistock

A CSV is in fact a simple text file in were all of the camps of the database
are separated by COMAS "," if a field contains a coma in the body the field
starts with ".

Ie
---START OF CSV FILE ---
Juan,C,Lopez,Some Addres,Some email<enter>
Juan,C,Lopez,Some Addres,"email1,email2"<enter>
---END OF CSV FILE ---

------------------------
Juan Carlos Lopez
QDesigns President & CEO
http://www.qdesigns.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

dragn...@my-dejanews.com

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
Hhhooooooooo!! thats a DIF file!

Well if you JUST want to convert it from CSV or TXT(in Tab Separated Format)
to DIF (or LDIF) open your excel program and open and export the data base to
DIF format! =-)

But if you want to make a Perl program that converts from CVS to DIF that will
be a problem! Because you have to learn the DIF format.

Ok For every body that wants to program in DIF format or in CSV or IN ANY
KNOWN WAY OF DATA SHEETS go here http://www.wotsit.org/ and in the database
section you can find how to read/save files even in excel! wow! hahahaha
(well if you can understand the excel standard! is sucks!)

Here is an example of a CSV file and a DIF file!
***CSV FILE***
1,Pen,12,12
2,Book,13,26
3,pencil,14,42
4,book2,15,60

*** DIF format ***
TABLE
0,1
"EXCEL"
VECTORS
0,4
""
TUPLES
0,4
""
DATA
0,0
""
-1,0
BOT
0,1
V
1,0
"Pen"
0,12
V
0,12
V
-1,0
BOT
0,2
V
1,0
"Book"
0,13
V
0,26
V
-1,0
BOT
0,3
V
1,0
"pencil"
0,14
V
0,42
V
-1,0
BOT
0,4
V
1,0
"book2"
0,15
V
0,60
V
-1,0
EOD

Soo you have to learn how to read DIF files! =-) (Why make the live soo hard!)

Craig Berry

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
Bart Lateur (bart....@skynet.be) wrote:

: Craig Berry wrote:
: >"Comma separated values". Typically, in addition to commas separating
: >values, values may be double-quoted strings to protect internal commas,
: >and double quotes inside such strings may be backslashed to protect them.
:
: Ouch. I don't think quotes are backslashed. Otherwise, you'd have to
: backslash backslashes too. Quotes are generally *doubled*.

I've run into both variants, actually. Thanks for pointing out the other
one.

Martien Verbruggen

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
In article <79se2s$qbf$1...@nnrp1.dejanews.com>,

dragn...@my-dejanews.com writes:
> In article <36C0A261...@cs.berkeley.edu>,
> Aaron Tavistock <aaro...@cs.berkeley.edu> wrote:
>> What is a CSV file?

> A CSV is in fact a simple text file in were all of the camps of the


> database are separated by COMAS "," if a field contains a coma in
> the body the field starts with ".

Is that where you have to have a

while ($brain->isInactive())
{
sleep($very_long);
}

in your code?

Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Can't say that it is, 'cause it ain't.
NSW, Australia |

Ronald J Kimball

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
What is LDAP?

(How long can we keep this going? ;-)


Martin Lönnar <martin...@edt.ericsson.se> wrote:

> LDIF = LDAP Data Interchange Format.
>
> /martin
>
> Steve Palincsar wrote:
>
> > CSV stands for "commas separated value" and there
> > is a perl module in CPAN to help you parse it.
> >
> > What is LDIF?
> >

> > Aaron Tavistock wrote:
> > >
> > > What is a CSV file?
> > >

> > > I've done alot of scripts for converting other formats into LDIF, but I
> > > have no idea what CSV is.
> > >
> > > Aaron Tavistock
> > >

> > > Martin Lönnar wrote:
> > > >
> > > > Hi,
> > > >
> > > > Is there a script/module to quickly convert CSV files to LDIF files?
> > > >
> > > > /martin lönnar


--
_ / ' _ / - aka - r...@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chip...@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."

Martin Lönnar

unread,
Feb 11, 1999, 3:00:00 AM2/11/99
to
LDAP = Lightweight Directory Access Protocol

Have a look at: http://ftp.sunet.se/foldoc/foldoc.cgi?query=ldap

I don't think we can go any deeper than this! :-)
(Of course we can, but I don't want to.)

/martin

dr...@copyright.com

unread,
Feb 11, 1999, 3:00:00 AM2/11/99
to
In article <1dn16nl.1ad...@bay1-169.quincy.ziplink.net>,
r...@linguist.dartmouth.edu (Ronald J Kimball) wrote:
> What is LDAP?
>

LDAP = Lightweight Directory Access Protocol.

> (How long can we keep this going? ;-)
>

I think that just about does it. Now if we'd started with a recursive acronym
it could have gone on forever. ;-)

> Martin Lönnar <martin...@edt.ericsson.se> wrote:
>
> > LDIF = LDAP Data Interchange Format.
> >
> > /martin
> >
> > Steve Palincsar wrote:
> >
> > > CSV stands for "commas separated value" and there
> > > is a perl module in CPAN to help you parse it.
> > >
> > > What is LDIF?
> > >

--
Don Roby

dr...@copyright.com

unread,
Feb 11, 1999, 3:00:00 AM2/11/99
to
In article <79sfj6$rko$1...@nnrp1.dejanews.com>,

dragn...@my-dejanews.com wrote:
> Hhhooooooooo!! thats a DIF file!
>

Oh?

> Well if you JUST want to convert it from CSV or TXT(in Tab Separated Format)
> to DIF (or LDIF) open your excel program and open and export the data base to
> DIF format! =-)
>
> But if you want to make a Perl program that converts from CVS to DIF that will
> be a problem! Because you have to learn the DIF format.
>
> Ok For every body that wants to program in DIF format or in CSV or IN ANY
> KNOWN WAY OF DATA SHEETS go here http://www.wotsit.org/ and in the database
> section you can find how to read/save files even in excel! wow! hahahaha
> (well if you can understand the excel standard! is sucks!)
>

All good advice if we were talking about a DIF file.

I think we're not.

The wotsit site is indeed a good resources, but it doesn't seem to know LDIF.
Perhaps that's because LDIF is pretty new, and not yet standardized.

As noted elsewhere in this thread, LDIF is a data interchange format used by
LDAP, a directory access protocol derived from the X.500 ISO standard. LDIF
will someday be defined by an IETF standard (aka RFC). Right now, it's in
draft and should be regarded as a "work in progress".

The latest Internet draft on LDIF can be found at
http://search.ietf.org/internet-drafts/draft-good-ldap-ldif-02.txt
and was just put there on Feb 1.

Further info on LDAP (and probably LDIF as well) is available at
http://www.umich.edu/~dirsvcs/ldap.

But we digress... ;-)

Jonathan Stowe

unread,
Feb 13, 1999, 3:00:00 AM2/13/99
to
On Wed, 10 Feb 1999 10:45:24 +0100 Martin Lönnar wrote:
> LDIF = LDAP Data Interchange Format.
>

Right now we've got that sorted out we can get down to it ;-}

You can use the module Text::CSV (or some code derived from the example in
perlfaq5) to split your input file's fields into the appropriate variables
and then for each record print these records in the appropriate manner
for LDIF. Because I neither know the format of your input file nor
remember the format of LDIF (beyond that is contains multiline records) I
wont attempt an example.

/J\
--
Jonathan Stowe <j...@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>

Russell Schulz

unread,
Feb 24, 1999, 3:00:00 AM2/24/99
to
bart....@skynet.be (Bart Lateur) quotes and writes:

>> "Comma separated values". Typically, in addition to commas
>> separating values, values may be double-quoted strings to protect
>> internal commas, and double quotes inside such strings may be
>> backslashed to protect them.
>
> Ouch. I don't think quotes are backslashed. Otherwise, you'd have to
> backslash backslashes too. Quotes are generally *doubled*.

Bart is correct.

from the comp.apps.spreadsheets FAQ:

if a comma is needed, the entire field will be surrounded by
quotation marks (though there is software that gets even this
wrong -- the Windows NT 3.51 Event Log export function is one
example). some packages enclose any string value (and even numeric
values) in quotation marks. to represent a quotation mark within
a field, double it (don't use `\"') and quote the whole field.
--
Russell...@locutus.ofB.ORG Shad 86c

0 new messages