[Haskell-cafe] Efficient way to edit a file

Donald Bruce Stewart dons at cse.unsw.edu.au
Thu Jun 1 22:07:34 EDT 2006

>   Hi,
>   I need to edit big text files (5 to 500 Mb). But I just need to 
> change one or two small lines, and save it. What is the best way to do 
> that in Haskell, without creating copies of the whole files?

I'd think maybe a lazy bytestring would be ok.

Something like:
  import Data.ByteString.Lazy.Char8
  B.putStr . B.unlines . B.map edit . B.lines =<< B.getContents

in the darcs version of Data.ByteString, here, http://www.cse.unsw.edu.au/~dons/fps.html
Let me know how you go, it would make a good benchmark.

-- Don

More information about the Haskell-Cafe mailing list