Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

String manipulation & file I/O

Name: Anonymous 2007-05-13 1:42 ID:a16QPoC4

I have a text file full of thousands of md5 hashes from around the interwebs but they are seperated with newlines.

I need to open the txt hash file, and write to another file but replacing every newline with nothing.

Possible languages: Perl, C++ or Visual Basic 6.

Name: Anonymous 2007-05-13 15:21 ID:WzmyTv6c

Please write in a real language:
module Main (main) where

import Prelude hiding (writeFile, readFile, filter)
import Data.ByteString.Char8
import System.Environment

main :: IO ()
main = do
    arg <- getArgs
    case arg of
      [from,to] -> do
        content <- readFile from
                    `catch` (\_ -> fail $ "file does not exit: " ++ from)
        writeFile to (filter (== '\n') content)
         `catch` (\_ -> fail $ "could not write to file: " ++ to)
      _      ->
        fail "invalid arguments. use <fromfile> <tofile>"

This has the advantage of actually being fast:
[code]$ wc irc/Updike\,\ John\ -\ Rabbit\,\ Run\(v1.1\)\[htm\].html
 11617 102746 615253 irc/Updike, John - Rabbit, Run(v1.1)[htm].html

$ time ./whut irc/Updike\,\ John\ -\ Rabbit\,\ Run\(v1.1\)\[htm\].html blah

real    0m0.010s
user    0m0.004s
sys     0m0.004s
[code]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List