Skip to content

Instantly share code, notes, and snippets.

@flazz
Created September 24, 2009 15:11
Show Gist options
  • Save flazz/192789 to your computer and use it in GitHub Desktop.
Save flazz/192789 to your computer and use it in GitHub Desktop.
module Main where
import System (getArgs)
import Text.RegexPR
-- matches lines against a pattern
grep :: String -> [String] -> [String]
grep p = filter $ match
where match s = case matchRegexPR p s of
Just _ -> True
Nothing -> False
-- take standard in filter through grep, out to standard out
main :: IO ()
main = do
args <- getArgs
let [pattern] = args
interact $ unlines . (grep pattern) . lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment