A console app that allows you to perform a search within a comma-separated values (CSV) file.
To start the solution, it must be installed in your machine:
I used the following Nuget packages:
- CsvHelper is a .NET library for reading and writing CSV files.
- Castle Windsor is a mature Inversion of Control container available for .NET.
The application receives as command line arguments the path to a CSV file to import, a column number to search in and a keyword. It is invoked as follows:
$ CsvParser.exe ./file.csv 2 Alberto
The CSV file is formatted as in the example below:
1,Rossi,Fabio,01/06/1990
2,Gialli,Alessandro,02/07/1989
3,Verdi,Alberto,03/08/1987
4,Rossi,Giacomo,12/03/1994
Taking into consideration the arguments passed to the application with the data in the example, the following output will be produced:
3,Verdi,Alberto,03/08/1987
Before starting the search operation, it checks are carried out on the number of arguments entered and on the arguments themselves. For example, it checks that the specified file exists.
The search is case insensitive, so searching for "Alberto" or "alBertO" in column number 2 will produce the same result. Separate discussion for the ID and date of birth which must be written correctly in order to be found.
In case of equal values, the application will return the first result found.
Licensed under the MIT license.