Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.