Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Perl Programming Language

parsing a csv file with a blob of text


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);
On 05/29/2007 08:50 PM, mike@gmail.com wrote:

> 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.

mike@gmail.com wrote:
> 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
     }

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc