Skip to content

Instantly share code, notes, and snippets.

@Javran
Created January 6, 2013 05:26
Show Gist options
  • Save Javran/4465426 to your computer and use it in GitHub Desktop.
Save Javran/4465426 to your computer and use it in GitHub Desktop.
sort csv file by column...
import Data.List
import Data.List.Split
strToTable raw = map (splitOn ",") rawRowList where
rawRowList = splitOn "\n" raw
tableToStr table = strJoin "\n" rawRowList where
rawRowList = map (strJoin ",") table
strJoin :: String -> [String] -> String
strJoin separator (x:xs) = foldl (\acc i->acc++separator++i) x xs
strJoin _ [] = []
main = do
content <- readFile "D:\\data.csv"
writeFile "D:\\data_sorted.csv" $ tableToStr $ sort $ strToTable content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment