Skip to content

Instantly share code, notes, and snippets.

@macintux
Created July 19, 2013 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macintux/6034995 to your computer and use it in GitHub Desktop.
Save macintux/6034995 to your computer and use it in GitHub Desktop.
Script to split large Riak cluster info outputs
#!/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