parsing a csv file with a blob of text

M

mikegws

I've got a script output that's run on dozens of systems and outputs
into a huge csv file. I'm new
at perl and would use Text:CSV but it doesn't understand the blob of
text in ""'s.

Right now I just need to break up the file into a directory for linux,
directory for solaris and put
the blob output in quotes for that hostname into a file in that dir.

I'm not sure how to properly read the blob from beginning to end and
key it off the hostname. Any
ideas?

------------
unixsys52,Solaris8,UltraSPARC-II 296Mhz,1024,"********


Creating a report on all Elan SG products installed on this system

-----------------***********************-----------------

License Key = R8PE-PDIY-NEGG-D34H-6PPP-3PPP-
K3OX
Product Name = Elan Dynatek Help Desk 4.0
Serial Number = 93692
Features :=

********",

(repeat over and over for each new system)

----------------Script-----------------

#!/usr/bin/perl

use File::path;

my $file = 'licenseout.csv';
my $licfile = "license.txt";

open (F, $file) || die ("Could not open $file!");

while (<F>)
{
if (/UltraSPARC/) {
($hostname,$osver,$proc,$ram,$elanlic) = split ',',
$_;
mkpath "/tmp/elic-solaris/$hostname";
chdir "/tmp/elic-solaris/$hostname";
if (/,"*.."/) {
open (LC, ">>$licfile");
print LC "$_";
}
}
}
if (/Intel/) {
($hostname,$os,$osver,$proc,$ram,$elanlic) = split
',', $_;
mkpath "/tmp/elic-linux/$hostname";
chdir "/tmp/elic-linux/$hostname";
if (/,"*.."/) {
open (LC, ">>$licfile");
print LC "$_";
}
}
}

close (F);
 
M

Mumia W.

I've got a script output that's run on dozens of systems and outputs
into a huge csv file. I'm new
at perl and would use Text:CSV but it doesn't understand the blob of
text in ""'s.
[...]

Check out the "binary" option for Text::CSV.
 
G

Gunnar Hjalmarsson

I've got a script output that's run on dozens of systems and outputs
into a huge csv file. I'm new
at perl and would use Text:CSV but it doesn't understand the blob of
text in ""'s.

Right now I just need to break up the file into a directory for linux,
directory for solaris and put
the blob output in quotes for that hostname into a file in that dir.

I'm not sure how to properly read the blob from beginning to end and
key it off the hostname. Any
ideas?

How about something like:

my $data = do { local $/; <F> };

while ( $data =~ /(.+?),"(.+?)",/gs ) {
my ($hostname, $osver, $proc, $ram) = split /,/, $1;
my $elanlic = $2;

# do whatever you want
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top