Skip to content

Instantly share code, notes, and snippets.

@vermorel
Last active December 19, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vermorel/6008628 to your computer and use it in GitHub Desktop.
Save vermorel/6008628 to your computer and use it in GitHub Desktop.
Tiny stand-alone flat file sampling utility.
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace Loader
{
class FlatSampling
{
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine(
@"Flat file sampling utility.
Usage
flatsamping.exe filename samplerate
Where:
'filename' is the target file
'samplerate' is an integer representing sampling rate
");
return;
}
string source = args[0];
var rate = int.Parse(args[1]);
if (source.EndsWith(".gz"))
{
using (var file = new FileStream(source, FileMode.Open))
using (var zip = new GZipStream(file, CompressionMode.Decompress))
using (var reader = new StreamReader(zip, Encoding.UTF8))
{
Read(reader, rate);
}
}
else
{
using (var file = new FileStream(source, FileMode.Open))
using (var reader = new StreamReader(file, Encoding.UTF8))
{
Read(reader, rate);
}
}
}
private static void Read(StreamReader reader, int rate)
{
int lineIndex = 0;
string line = null;
while ((line = reader.ReadLine()) != null)
{
if(lineIndex++ % rate == 0) Console.WriteLine(line);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment