JMP report file .jrp file to csv

Here’s a quick and dirty Perl script to get a data table out of a .jrp file from JMP.  Not guaranteed to work for all files, as I’ve only tested it on one (so modification may be necessary).

#! /usr/bin/perl -w

use strict;
use Getopt::Long;
my $jmp_file;
my $colhead;
my $values;
my $row;
my @records;
my $ndata; 
GetOptions ('jmp=s' => \$jmp_file) or die("Error in arguments\n");

open (JMP,"<$jmp_file") || die "cannot open JMP input file $jmp_file";
while(<JMP>){
chomp;
if($_=~/New Column\(\s\"(.+?)\",.+$/){ # Get column names
 $colhead=$1;
}
if($_=~/Set Values\(\s[\[\{](.+?)[\]\}] \) \),/){ # Get row values
$values=$1;
my @row = split ", ", $values;
unshift @row, $colhead;
$ndata= scalar @row;
push @records, \@row;
}
}

# Rotate table 90 degrees (rows-to-columns)
my $nrecords=scalar @records;
for(my $i=0;$i<$ndata; $i++){
for(my $j=0;$j<$nrecords;$j++){
print "$records[$j][$i]";
print "," if $j<($nrecords-1) 
}
print "\n";
}
Advertisements

Leave a comment...

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s