Is there a script/module to quickly convert CSV files to LDIF files?
/martin lönnar
I've done alot of scripts for converting other formats into LDIF, but I
have no idea what CSV is.
Aaron Tavistock
"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."
What is LDIF?
Aaron Tavistock wrote:
>
> What is a CSV file?
>
/martin
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
>"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.
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
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!)
I've run into both variants, actually. Thanks for pointing out the other
one.
> 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 |
(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."
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
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
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... ;-)
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>
>> "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