Splitting and Sorting a CSV File in Command Line

I’ve been moving some data using some CSV (Comma separated) files. There is no direct command in Windows to split or sort files. Unless you do it in Excel or Open Office. So I installed Cygwin. Here are a few examples in Cygwin or most Unix based shells how to split and sort files.

Example 1
There is a big file you want to split into smaller files.

split in.csv out.

split automatically splits 1000 lines each. If you want another number use -l 500 to get 500 lines.

split -l 500 in.csv out.

Example 2
You want to sort the second field in a CSV file in numeric order.

sort -n -k 2 in.csv > out.csv

For more details look up up the split and sort manuals.

man split

man sort