System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Coverting csv file to binary

 
SOLVED
Go to solution
Highlighted
Super Advisor

Coverting csv file to binary

Hi guys,

Is there a way to covert csv file to its binary equivalent. I have attached the sample files.

Hope u guys can help me out..
thanks!!

Henry
19 REPLIES 19
Highlighted
Super Advisor

Re: Coverting csv file to binary

attached is its binary file equivalent..
Highlighted
Honored Contributor

Re: Coverting csv file to binary

can you tell us what the "binary" format is?

I've looked at the binary file but it has things missing from the original file.

I even saw a backspace character in it (which is weird for a file format).

How did you get the cvs file into that binary format?

live free or die
harry d brown jr
Live Free or Die
Highlighted
Honored Contributor

Re: Coverting csv file to binary

# perl -MText::CSV_XS -le'$c=Text::CSV_XS->new({binary=>1});while(<>){$c->parse($_);print$c->fields}' file.csv > file.dta

BUT!

M$ has never been able to read the specs. CSV is shorthand for COMMA Separated Values, and guess what M$ uses? Right, a semicolon. So in order to convert microshit generated csv files, you need

# perl -MText::CSV_XS -le'$c=Text::CSV_XS->new({binary=>1,sep_char=>";"});while(<>){$c->parse($_);print$c->fields}' file.csv > file.dta

HTH, Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Highlighted
Honored Contributor

Re: Coverting csv file to binary

If you are trying to import the cvs file into M$ decel (I mean excel) then just use the wizard and change the default from a ; to a ,

live free or die
harry d brown jr
Live Free or Die
Highlighted
Super Advisor

Re: Coverting csv file to binary

Hi MeiJin,

Sorry I am new to Perl, can u explain how your script actually works.. I tried running it on my system. doesnt seem to work

Best regards
Henry
Highlighted
Super Advisor

Re: Coverting csv file to binary

Hi Harry,

What I really want to do is to convert csv file to its binary equivalent. This binary file is generated by a customise program, in actual I am not even sure if the conversion is possible.. just trying my luck..

Thanks!! =)

regards
Henry
Highlighted
Honored Contributor
Solution

Re: Coverting csv file to binary

I've never before seen my name spelt like that :)

perl -MText::CSV_XS -le'$c=Text::CSV_XS->new({binary=>1,sep_char=>";"});while(<>){$c->parse($_);print$c->fields}' file.csv > file.dta

is more verbose,as a script, more or less the same as (with comments):

--8<--- csv2bin.pl
#!/opt/perl/bin/perl
# this line tell where your perl resides

use strict; # Don't allow ambiguous code
use warnings; # Warn me wherever appropriate

use Text::CSV_XS; # use the Text::CSV_XS module.
# Should be installed from CPAN or bundled in the port you got

my $csv = Text::CSV_XS->new ({ # create a new csv handle
binary => 1, # that uses binary data
sep_char => ";", # and a semicolon as separator
});

# Now parse the input lines
while (<>) {
$csv->parse ($_); # break down as valid csv
print $csv->fields; # and print the fields as binary
}
-->8---

First check if you have perl, and what version:

# perl -v

If you don't have it (yet), you can get it from my site, and my builds include CSV_XS

My HP ITRC site pages can be found at (please use LA as primary choice):

USA Los Angeles http://mirrors.develooper.com/hpux/
SGP Singapore https://www.beepz.com/personal/merijn/
USA Chicago http://ww.hpux.ws/merijn/
NL Hoofddorp http://www.cmve.net/~merijn/

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Highlighted
Super Advisor

Re: Coverting csv file to binary

Hi Merijn,

Sorry for getting your name wrong. =p

I have gotten this when i probed the machine.

This is perl, version 4.0

$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36

Copyright (c) 1989, 1990, 1991, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 4.0 source kit.

Will this version work? Where can I grt the "CSV_XS" for this version?

Thank u for your help..

=)
Regards
Henry



Highlighted
Honored Contributor

Re: Coverting csv file to binary

Perl 4 is basically useless except to run the q4 dump analyzer. Perl 5 should be downloaded from software.hp.com and installed on your machine.


Bill Hassell, sysadmin