- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Coverting csv file to binary
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2005 08:48 PM
тАО04-04-2005 08:48 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2005 08:49 PM
тАО04-04-2005 08:49 PM
Re: Coverting csv file to binary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 12:19 AM
тАО04-05-2005 12:19 AM
Re: Coverting csv file to binary
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 12:36 AM
тАО04-05-2005 12:36 AM
Re: Coverting csv file to binary
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 12:40 AM
тАО04-05-2005 12:40 AM
Re: Coverting csv file to binary
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 01:00 AM
тАО04-05-2005 01:00 AM
Re: Coverting csv file to binary
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 01:03 AM
тАО04-05-2005 01:03 AM
Re: Coverting csv file to binary
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 01:14 AM
тАО04-05-2005 01:14 AM
Solutionperl -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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 01:29 PM
тАО04-05-2005 01:29 PM
Re: Coverting csv file to binary
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 02:00 PM
тАО04-05-2005 02:00 PM
Re: Coverting csv file to binary
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2005 04:15 AM
тАО04-06-2005 04:15 AM
Re: Coverting csv file to binary
I gotten this when I try to run the script..
"Can't locate Text/CSV_XS.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-l.
BEGIN failed--compilation aborted at ./test line 7."
do you know what i did wrong? how can i get the csv_xs.pm package?
best regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2005 12:25 PM
тАО04-08-2005 12:25 PM
Re: Coverting csv file to binary
Manage to fix the problem and make the module work. However, I was wondering whether i could modify the script to convert binary to csv as well..
can be done?
Best regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2005 05:15 AM
тАО04-09-2005 05:15 AM
Re: Coverting csv file to binary
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2005 05:45 AM
тАО04-09-2005 05:45 AM
Re: Coverting csv file to binary
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2005 07:15 AM
тАО04-09-2005 07:15 AM
Re: Coverting csv file to binary
Spreadsheet::WriteExcel and Date::Calc are both included in my perl builds and are available on CPAN. The advantage of writing xls yourself, instead of having M$-Excel do it on import or open is that you have control over the dates, instead of having M$ fuck-up all valid dates to be forced to braindead US format
Also attached to have your script retain format. Hey, I even have a usage sub :)
--8<--- append_csv
#!/pro/bin/perl
use strict;
use warnings;
sub usage ()
{
print STDERR
"usage: $0 [-c utf8|iso8859] [-i
",
" $0 -x [-c utf8|iso8859] [-d
utfile\n";
exit;
} # usage
use Getopt::Long qw( :config bundling nopermute);
my $codep = $ENV{UTF8_OK} // 0 ? "utf8" : "iso8859-1";
my $i_sep = qr/\s*\|\s?/;
my $o_sep = ",";
my $pfx = "";
my $xls = 0;
my $dtf = "dd-mm-yyyy"; # Excel date format
my $wdt = 4; # Default minimal column width
GetOptions (
"c|codep=s" => \$codep,
# CSV stuff
#!/pro/bin/perl
use strict;
use warnings;
sub usage ()
{
print STDERR
"usage: $0 [-c utf8|iso8859] [-i
",
" $0 -x [-c utf8|iso8859] [-d
utfile\n";
exit;
} # usage
use Getopt::Long qw( :config bundling nopermute);
my $codep = $ENV{UTF8_OK} // 0 ? "utf8" : "iso8859-1";
my $i_sep = qr/\s*\|\s?/;
my $o_sep = ",";
my $pfx = "";
my $xls = 0;
my $dtf = "dd-mm-yyyy"; # Excel date format
my $wdt = 4; # Default minimal column width
GetOptions (
"c|codep=s" => \$codep,
# CSV stuff
"i=s" => sub { $i_sep = qr{$_[1]} },
"o|csv=s" => \$o_sep,
"m|ms" => sub { $o_sep = ";" }, # Micro$hit expects semi-colon
# Excel stuff
"x|xls|excel" => \$xls,
"d|date=s" => \$dtf,
"w|cwidth=i" => \$wdt,
) or usage;
use Text::CSV_XS;
use Date::Calc qw( Delta_Days );
use Spreadsheet::WriteExcel;
use PROCURA::Diac;
my $mode = $0 =~ m/clr/ ? "> " : ">> ";
if (@ARGV) {
my $ofile = shift;
if ($xls) {
($xls = $ofile) =~ s/(\.xls)?$/.xls/i;
}
else {
open STDOUT, "$mode $ofile" or die "$ofile: $!\n";
}
}
elsif ($xls) {
die "Excel formaat kan niet naar stadaard uit.\n";
}
my ($h, $w, $csv, $wbk, $wks, %fmt, @w) = (0, 1);
if ($xls) {
$wbk = Spreadsheet::WriteExcel->new ($xls);
$wks = $wbk->add_worksheet ();
%fmt = (
date => $wbk->add_format (align => "center", num_format => $dtf),
rest => $wbk->add_format (align => "left"),
);
}
else {
$csv = Text::CSV_XS->new ({
binary => 1,
sep_char => $o_sep,
always_quote => 1,
});
}
my $p_tex = $codep =~ m/^u(tf-?8|nicode)$/i ? \&TexUnicode : # utf-8, utf8, unic
ode
$codep =~ m/8859\D9|latin5/i ? \&Tex8859_9 : # iso8859-9, latin5
$codep =~ m/none|strip|cs7/i ? \&TexNone : # none, strip, cs7
\&Tex8859_1; # * (iso8859-1, lat
in1)
$p_tex == \&TexUnicode and binmode STDOUT, ":utf8";
while (<>) {
chomp;
m/\S/ or next;
s/^\s+//;
my @row = split $i_sep, $_, -1;
if ($xls) {
@row > $w and push @w, ($wdt) x (($w = @row) - @w);
foreach my $c (0 .. $#row) {
(my $val = $row[$c]) =~ s/^\s+//;
my $l = length $val;
$l > $w[$c] and $w[$c] = $l;
my @d = (0, 0, 0); # Y, M, D
$val =~ m/^(\d{4})(\d{2})(\d{2})$/ and @d = ($1, $2, $3);
$val =~ m/^(\d{2})-(\d{2})-(\d{4})$/ and @d = ($3, $2, $1);
if ($d[1] >= 1 && $d[1] <= 12 && $d[0] >= 1900) {
my $dt = 2 + Delta_Days (1900, 1, 1, @d);
$wks->write ($h, $c, $dt, $fmt{date});
next;
}
if ($val =~ m/^[\d.]{10,}$/) {
# Excel will convert long numericals to float
# 1000101222101220 ...
# It's in this case much more likely that it is a string
$wks->write_string ($h, $c, $val);
}
else {
$wks->write ($h, $c, $val);
}
}
}
else {
unless ($csv->combine (@row)) {
print STDERR "Data error: ", $csv->error_input, "\n";
exit;
}
print $p_tex->($csv->string), "\r\n";
}
++$h % 100 or printf STDERR "%6d x %6d\r", $w, $h;
}
if ($xls) {
$wks->set_column ($_, $_, $w[$_]) for 0 .. $#w;
$wbk->close ();
}
close STDOUT;
-->8---
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-10-2005 08:42 PM
тАО04-10-2005 08:42 PM
Re: Coverting csv file to binary
Many thanks for the script. I am in the midst of digesting - quite a big for my level.
One last thing I would like to know is whether converting binary to text is possible? if so can I used CSV_XS to achieve this?
I am terribly sorry for constant queries. Thanks for your invaluable assistance.
Best regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-10-2005 08:55 PM
тАО04-10-2005 08:55 PM
Re: Coverting csv file to binary
Do you consider UTF8 binary? Or Unicode? Or even iso-8859-1?
If your defenition of "Text" is plain US-ASCII 7 bit, yes, it's probably possible, most likely possible even. But your conversion will not be lossless
What is "Binary" and what is "Text". That is the crucial question in your quest. Once you can answer that unambigouously, my answer would probably be "yes"
If your def of Binary is "fixed width records" that should be converted to html or other text based data files, do
# man perlpacktut
and teach yourself unpack
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2005 01:55 AM
тАО04-12-2005 01:55 AM
Re: Coverting csv file to binary
From a look at a binary file is it possible to tell which coding it is using? For example the binary file I provided in the begining of the query, can you tell which format is it using?
And many thanks, You have been really been a great help, sorry if my question look weird to u..
Regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2005 02:31 AM
тАО04-12-2005 02:31 AM
Re: Coverting csv file to binary
a5:/tmp 102 > file *.null
226232.null: lif file
a5:/tmp 103 > lifls *.null | head
WS_FILE
a5:/tmp 104 >
There are several LIF commands:
lifcp, lifinit, lifls, lifrename, and lifrm
a5:/tmp 108 > lifls -l *null
volume HFSLIF data size 1052 directory size 1
filename type start size implement created
===============================================================
WS_FILE -5791 2 121 20200080 00/00/00 00:00:00
a5:/tmp 109 >
Now, maybe, you might mean that you want to know the format of WS_FILE
a5:/tmp 110 > lifcp 226232.null:WS_FILE .
a5:/tmp 111 > file WS_FILE
WS_FILE: data
a5:/tmp 112 >
Looking at the hex-dump of WS_FILE, it looks very parsable and very binary (about Volt, Ampere, and Ohm). Since I have no idea what it is, I cannot give you any guidelines here
00000100 00 00 00 06 52 36 39 34 30 32 00 00 00 06 52 36 ....R69402....R6
00000110 39 34 30 32 00 00 00 07 53 55 42 53 49 54 45 20 9402....SUBSITE
00000120 00 00 00 07 53 55 42 53 49 54 45 20 00 00 00 08 ....SUBSITE ....
00000130 4E 56 74 68 69 28 31 29 00 00 00 07 4E 49 64 73 NVthi(1)....NIds
00000140 28 31 29 20 00 00 00 08 4E 56 74 68 69 28 32 29 (1) ....NVthi(2)
00000150 00 00 00 08 4E 49 6F 66 66 28 32 29 00 00 00 07 ....NIoff(2)....
00000890 00 00 00 00 00 03 49 44 53 20 00 00 00 07 53 55 ......IDS ....SU
000008A0 42 53 49 54 45 20 00 00 00 04 56 54 48 46 00 00 BSITE ....VTHF..
000008B0 00 03 49 44 53 20 00 00 00 04 56 54 48 46 00 00 ..IDS ....VTHF..
000008C0 00 06 49 44 53 4F 46 46 00 00 00 03 49 44 53 20 ..IDSOFF....IDS
000008D0 00 00 00 05 42 56 44 53 53 20 00 00 00 08 56 54 ....BVDSS ....VT
000008E0 48 4C 43 44 32 46 00 00 00 03 49 44 53 20 00 00 HLCD2F....IDS ..
000008F0 00 08 56 54 48 4C 43 44 32 46 00 00 00 06 49 44 ..VTHLCD2F....ID
00000EC0 00 00 00 00 00 00 00 00 00 01 41 20 00 00 00 01 ..........A ....
00000ED0 41 20 00 00 00 01 56 20 00 00 00 01 41 20 00 00 A ....V ....A ..
00000EE0 00 01 56 20 00 00 00 01 41 20 00 00 00 01 41 20 ..V ....A ....A
00000EF0 00 00 00 01 56 20 00 00 00 01 56 20 00 00 00 01 ....V ....V ....
00000F00 41 20 00 00 00 01 56 20 00 00 00 01 41 20 00 00 A ....V ....A ..
00000F10 00 01 41 20 00 00 00 01 41 20 00 00 00 01 56 20 ..A ....A ....V
00000F20 00 00 00 01 56 20 00 00 00 01 41 20 00 00 00 01 ....V ....A ....
00000F30 41 20 00 00 00 01 41 20 00 00 00 01 56 20 00 00 A ....A ....V ..
00000F40 00 01 56 20 00 00 00 01 41 20 00 00 00 01 56 20 ..V ....A ....V
00000F50 00 00 00 01 56 20 00 00 00 06 4F 68 6D 2F 5B 5D ....V ....Ohm/[]
00000F60 00 00 00 06 4F 68 6D 2F 5B 5D 00 00 00 06 4F 68 ....Ohm/[]....Oh
00000F70 6D 2F 5B 5D 00 00 00 01 41 20 00 00 00 01 56 20 m/[]....A ....V
000016A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000016B0 00 01 33 20 00 00 00 01 32 20 00 00 00 01 34 20 ..3 ....2 ....4
000016C0 00 00 00 01 31 20 00 00 00 00 00 00 00 00 00 00 ....1 ..........
000016D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000016E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000016F0 00 00 00 00 00 00 00 00 00 01 33 20 00 00 00 01 ..........3 ....
00001700 32 20 00 00 00 01 34 20 00 00 00 01 31 20 00 00 2 ....4 ....1 ..
00001710 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00001720 00 01 33 20 00 00 00 01 32 20 00 00 00 01 34 20 ..3 ....2 ....4
00001730 00 00 00 01 31 20 00 00 00 00 00 00 00 00 00 00 ....1 ..........
00001740 00 00 00 00 00 00 00 00 00 01 35 20 00 00 00 01 ..........5 ....
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-17-2019 09:11 PM
тАО01-17-2019 09:11 PM
Re: Coverting csv file to binary
What converter or code did you use to achieve this?