CsvSorter 1.1.0

dotnet add package CsvSorter --version 1.1.0                
NuGet\Install-Package CsvSorter -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CsvSorter" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CsvSorter --version 1.1.0                
#r "nuget: CsvSorter, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CsvSorter as a Cake Addin
#addin nuget:?package=CsvSorter&version=1.1.0

// Install CsvSorter as a Cake Tool
#tool nuget:?package=CsvSorter&version=1.1.0                

CsvSorter

alternate text is missing from this package README image

Build Tests Issues License Nuget

It is a small package that will help you to sort your large CSV files.

Instalation

PM> Install-Package CsvSorter

Dependencies

Package name Version
CsvHelper >=30.0.1

Avaliable methods

Method name Parameter type Description
OrderBy<T> string<br>int Describes CSV field type and name (or index) that are going to be used during the sorting.<br>Sort direction: ascending.
OrderByDescending<T> string<br>int Describes CSV field type and name (or index) that are going to be used during the sorting.<br>Sort direction: descending.
Using CsvConfiguration Sets CsvConfiguration. See CsvHelper documentation
TypeConverterOptions Sets TypeConverterOptions. See CsvHelper documentation
IIndexProvider<T> Alows to set index provider. Default: MemoryIndexProvider
ToFile string Saves sorted data to a file
ToWriter TextWriter Saves sorted data using provided writer

Usage example

using CsvSorter;
new StreamReader(@"C:\my_large_file.csv")
    .OrderBy<int>("id")
    .ToFile(@"C:\my_large_file_sorted_by_id.csv");

Index provider

Default index provider is MemoryIndexProvider<T>. It stores index data in the memory. You can create your own provider (DatabaseIndexProvider for example) by implementing IIndexProvider<T> interface:

public interface IIndexProvider<T> where T: IComparable
{
    void Add(CsvSorterIndex<T> record);
    IEnumerable<CsvSorterIndex<T>> GetSorted(bool descending);
    void Clear();
}

Events

You can specify 4 events: OnIndexCreationStarted, OnIndexCreationFinished, OnSortingStarted and OnSortingFinished

new StreamReader(@"C:\my_large_file.csv")
    .OrderBy<int>(0)
    .OnIndexCreationStarted(() => { logger.Info("Index creation has started"); })
    .OnIndexCreationFinished(() => { logger.Info("Index creation completed"); })
    .OnSortingStarted(() => { logger.Info("Sorting has started"); })
    .OnSortingFinished(() => { logger.Info("Sorting completed"); })
    .ToWriter(writer);

A few more examples

var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    HasHeaderRecord = false
};

var dateTimeConverterOptions = new TypeConverterOptions
{ 
    Formats = new[] { "dd_MM_yyyy" }
};

new StreamReader(@"C:\my_large_file.csv")
    .OrderByDescending<DateTime>(3)
    .Using(csvConfig)
    .Using(dateTimeConverterOptions)
    .ToFile(@"C:\my_large_file_sorted_by_date.csv");
var csvConfig = new CsvConfiguration(CultureInfo.InvariantCulture)
{
    Delimiter = "|"
};

new StreamReader(@"C:\my_large_file.csv")
    .OrderBy<string>("email")
    .Using(csvConfig)
    .Using(new AzureIndexProvider<string>())
    .ToWriter(writer);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 198 5/25/2023
1.0.2 356 11/2/2021
1.0.1 329 6/1/2021
1.0.0 346 5/31/2021