Created
January 6, 2013 05:26
-
-
Save Javran/4465426 to your computer and use it in GitHub Desktop.
sort csv file by column...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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