Skip to content

Instantly share code, notes, and snippets.

@mpfund
Created April 14, 2015 19:36
Show Gist options
  • Save mpfund/7a3ec4340322a30965f4 to your computer and use it in GitHub Desktop.
Save mpfund/7a3ec4340322a30965f4 to your computer and use it in GitHub Desktop.
find strings in files
import Data.ByteString.Lazy.Char8 as BS
import Data.Word
import Data.Bits
import Data.List
import Data.Char
import Data.List.Split
isChar x = o > 31 && o < 127 where o = ord x
scan::[Char]->[Char]->[Char]
scan (x:xs) (y1:y2:y3:_) = if isChar x then [y1]++scan xs [y2,y3,x] else [y1,y2,y3,'\n']++scan xs []
scan (x:xs) (y1:y2:_) = if isChar x then scan xs [y1,y2,x] else scan xs []
scan (x:xs) (y1:_) = if isChar x then scan xs [y1,x] else scan xs []
scan (x:xs) [] = if isChar x then scan xs [x] else scan xs []
scan [] (y1:y2:y3:_) = [y1,y2,y3]
scan [] _ = []
main = do
contents <- BS.readFile "inp"
let foundStr = scan (unpack contents) []
Prelude.writeFile "out.txt" foundStr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment