Created
March 14, 2014 14:38
-
-
Save maxmanders/9548978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use JSON; | |
my %results = (); | |
my $keyspace = 'None'; | |
my $table = 'None'; | |
while (<>) { | |
next if (/^xss/ || /----/ || /^\s*$/); | |
my $line = $_; | |
chomp($line); | |
if ($line =~ /^Keyspace/) { | |
$keyspace = (split(/:/, $line))[1]; | |
$keyspace =~ s/^\s+|\s+$//g; | |
$results{$keyspace} = (); | |
} elsif ($line =~ /\s+Table/) { | |
$table = (split(/:/, $line))[1]; | |
$table =~ s/^\s+|\s+$//g; | |
$results{$keyspace}{$table} = {}; | |
} else { | |
my ($key, $value) = split(/:/, $line); | |
$key =~ s/^\s+|\s+$//g; | |
$key =~ s/\s+/_/g; | |
$key = lc($key); | |
$value =~ s/^\s+|\s+$//g; | |
$value =~ s/\s+/_/g; | |
$value = lc($value); | |
if ($table eq 'None' && $keyspace ne 'None') { | |
$results{$keyspace}{$key} = $value; | |
} else { | |
$results{$keyspace}{$table}{$key} = $value; | |
} | |
} | |
} | |
print encode_json(\%results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment