Created
February 21, 2019 06:09
-
-
Save masakuni-ito/efc6773105a1430aa5f24cb3384b4c7a to your computer and use it in GitHub Desktop.
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/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