[Haskell-cafe] How to cut a file effciently?
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).
On Tue, Apr 7, 2009 at 11:20 PM, Magicloud Magiclouds <
magicloud.magiclouds at gmail.com> wrote:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe