Created
July 19, 2013 03:50
-
-
Save macintux/6034995 to your computer and use it in GitHub Desktop.
Script to split large Riak cluster info outputs
This file contains 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/perl -w | |
use strict; | |
use warnings; | |
## Running this script: | |
## 1 Set $datadir to whatever folder you'd like to store the new files | |
## 2 Run this script with your cluster info file as input | |
## $ ./split.pl < cluster-info.out | |
## | |
## Will display the filenames it creates as it creates them | |
my $datadir = "/tmp"; | |
my $node_name = 'unknown'; | |
my $fh = undef; | |
while(<STDIN>) { | |
if (/^== Node.*'(.*)@/) { | |
$node_name = $1; | |
next; | |
} | |
if (/^= (.*)/) { | |
my $filename = $1; | |
$filename =~ s/\W+/_/g; | |
$filename =~ s/_$//; # Drop any trailing _ | |
close($fh) if $fh; | |
$fh = undef; | |
$filename = sprintf("%s/%s-%s.info", | |
$datadir, $node_name, $filename); | |
print "Opening $filename\n"; | |
open($fh, ">$filename"); | |
print $fh $_; | |
next; | |
} | |
if ($fh) { | |
print $fh $_; | |
} | |
} | |
close($fh) if $fh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment