[Haskell-cafe] How to cut a file effciently?
Luke Palmer
lrpalmer at gmail.com
Wed Apr 8 01:32:22 EDT 2009
split n [] = []
split n xs = take n xs : split n (drop n xs)
main = do
text <- readFile "source"
mapM_ (\(n,dat) -> writeFile ("dest" ++ show n) dat) . zip [0..] . split
10000 . lines $ text
Modulo brainos... but you get the idea. This is lazy (because readFile is).
Luke
On Tue, Apr 7, 2009 at 11:20 PM, Magicloud Magiclouds <
magicloud.magiclouds at gmail.com> wrote:
> Hi,
> Let us say I have a text file of a million lines, and I want to cut
> it into smaller (10K lines) ones.
> How to do this? I have tried a few ways, none I think is lazy (I
> mean not reading the file all at the start).
> --
> ÖñÃÜÆñ·ÁÁ÷Ë®¹ý
> ɽ¸ßÄÄ×èÒ°ÔÆ·É
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090407/ca717072/attachment.htm
More information about the Haskell-Cafe
mailing list