Nobody will read your post.

That turned out not to be the case :)

I was curious how much time it would take me to move such data in a postgres table (with apologies to the OP but I just can't be bothered with the minor oracle stuff).

It took me 13 minutes.

Obviously the parsing is guesswork on my part.

use strict; use warnings; use DBI; my $t = "pm1083865_ivo"; # table name my $dbh = DBI->connect or die "no database connection - $!\n "; $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; $dbh->do("drop table if exists $t"); $dbh->do("create table $t(col0 timestamptz, col1 text, col2 int, col3 +text, col4 int)"); $dbh->commit; my $sth1 = $dbh->prepare("insert into $t values(cast(? as timestamptz) +,?,?)" ); my $sth2 = $dbh->prepare("insert into $t values(cast(? as timestamptz) +,?,?,?,?)"); my $date_string ; while (<>) { chomp; $date_string = $_; last; } while (<>) { no warnings 'uninitialized'; next if (/^\s*$/); my ($col1, $col2, $col3, $col4); s{\r}{}; chomp; if ( /^([^:]+):\s*(\d+)\s*$/ ) { $col1 = $1; $col2 = $2; $col3 = ''; $col4 = ''; $sth1->execute($date_string, $col1,$col2); } elsif ( /^([^:]+):\s*(\d+)\s*([^:]+):\s*(\d+)\s*$/ ) { $col1 = $1; $col2 = $2; $col3 = $3; $col4 = $4; $sth2->execute($date_string,$col1,$col2,$col3,$col4); } else { print ">>>", $_ ,"<<<\n"; die "oops - unprocessed line!\n"; } # print join("\t", $col1, $col2, $col3, $col4), "\n"; } $dbh->commit; $dbh->disconnect; $ wc -l pm1083865_ivo.txt 72 pm1083865_ivo.txt $ perl ivo.pl pm1083865_ivo.txt && echo "table pm1083865_ivo limit 5; +select count(*) from pm1083865_ivo" | psql Timing is on. col0 | col1 | col2 | col3 + | col4 ------------------------+-------------------+--------+---------------- +--+-------- 2014-04-25 23:06:25+02 | Total Subscribers | 970260 | + | 2014-04-25 23:06:25+02 | Active | 86806 | Dormant + | 883454 2014-04-25 23:06:25+02 | pdsn-simple-ipv4 | 212 | pdsn-simple-ipv +6 | 0 2014-04-25 23:06:25+02 | pdsn-mobile-ip | 539792 | ha-mobile-ipv6 + | 0 2014-04-25 23:06:25+02 | hsgw-ipv6 | 234943 | hsgw-ipv4 + | 1977 (5 rows) Time: 1.845 ms count ------- 70 (1 row) Time: 0.820 ms

UPDATE: change col0 to timestamptz; added a commit;


In reply to Re^2: Parsing cli output into .csv by erix
in thread Parsing cli output into .csv by Ivo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.