Skip to content

Instantly share code, notes, and snippets.

@masakuni-ito
Created February 21, 2019 06:09
Show Gist options
  • Save masakuni-ito/efc6773105a1430aa5f24cb3384b4c7a to your computer and use it in GitHub Desktop.
Save masakuni-ito/efc6773105a1430aa5f24cb3384b4c7a to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
open(FP, "< data.txt") or die("Error");
my @migrations = split(/Table name: .*?Migration File: /s, join('', <FP>));
close(FP);
my $cnt = 1;
my %files = ();
foreach my $migration (@migrations) {
$migration =~ /^(.*?)\n+(.*?)\n*$/s;
$file_name = $1;
$file_body = $2;
next if (!$file_name);
$tmp = sprintf('%06d', $cnt);
$file_name =~ s/000000/$tmp/;
$files{$file_name} = $file_body;
$cnt++;
}
mkdir './out' if (! -d './out');
foreach my $key (keys %files) {
open(FP, "> ./out/$key");
print FP $files{$key};
close(FP);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment