Created
December 8, 2014 12:37
-
-
Save CVertex/6c83770043e26e94af04 to your computer and use it in GitHub Desktop.
Splitting files by line using C#
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using C = System.Console; | |
using System.IO; | |
using System.Net; | |
namespace Commands | |
{ | |
public class SplitFile | |
{ | |
public void Run() | |
{ | |
C.WriteLine("Splitting a file.."); | |
var lines = File.ReadAllLines(@"insert-song-genres.sql"); | |
long totalLines = lines.LongCount(); | |
var outputFileFormat = @"insert-song-genres_part_{0}.sql"; | |
int skip = 0; | |
int count = 20000; | |
while (skip < totalLines) { | |
string outFile = String.Format(outputFileFormat,skip); | |
File.WriteAllLines(outFile,lines.Skip(skip).Take(count)); | |
skip += count; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment