Skip to content

Instantly share code, notes, and snippets.

@dreftymac
Last active May 5, 2016 19:35
Show Gist options
  • Save dreftymac/42d191388c042dbbddce472c17b273e6 to your computer and use it in GitHub Desktop.
Save dreftymac/42d191388c042dbbddce472c17b273e6 to your computer and use it in GitHub Desktop.
split a single large file into multiple smaller files // dreftymacid: ding_fresher_mesh
#!/usr/bin/perl
### <beg-file_info>
### main:
### - date: created="Thu May 05 12:16:56 2016"
### last: lastmod="Thu May 05 12:16:56 2016"
### tags: tags
### dreftymacid: "ding_fresher_mesh"
### filetype: "perl"
### seealso: |
### *
### desc: |
### split a large mysql export file into multiple files based on delimiter
### section within the file
### <end-file_info>
### begin_ init vars
$inppfile = "/path/to/file/database.sql";
$cur=0;
### begin_ main
open(FI,$inppfile) or die "Input file not found";
open(FO,">splitfile.$cur.txt") or die "Cannot open output file $cur";
while(<FI>)
{
print FO $_;
if(/^-- Table structure for/)
{
close(FO);
$cur++;
open(FO,">splitfile.$cur.txt") or die "Cannot open output file $cur"
}
}
close(FO);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment