with PCRE. now (and yep, it's a lot faster than posix):
*************************************************************************** [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ ./q-words.sh q qua quack quacked quackery quackery's quacking quacks quad quad's real 0m6.691s user 0m2.460s sys 0m3.000s q qua quack quacked quackery quackery's quacking quacks quad quad's real 0m1.032s user 0m0.750s sys 0m0.100s [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ cat q-words.sh time cat /usr/share/dict/american-english | ghc -e 'interact $ unlines. take 10 . filter ( \x -> x =~ "^q" :: Bool ) . lines' ImportsRegexPosix.hs time cat /usr/share/dict/american-english | ghc -e 'interact $ unlines. take 10 . filter ( \x -> x =~ "^q" :: Bool ) . lines' ImportsRegexPCRE.hs [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ cat ImportsRegexPosix.hs import Text.Regex.Posix [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ cat ImportsRegexPCRE.hs import Text.Regex.PCRE [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ 2007/3/7, Thomas Hartman <[EMAIL PROTECTED]>:
In the spirit of making easy things easy, here is a "haskell from shell" one-line grepper, that uses regexen. Now, if only I could get pcre-regex installed I would be quite content. (Still stuck using posix RE for now.) ************** [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ time ./q-words.sh q qua quack quacked quackery quackery's quacking quacks quad quad's real 0m3.186s user 0m1.900s sys 0m0.810s [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ cat q-words.sh cat /usr/share/dict/american-english | ghc -e 'interact $ unlines. take 10 . filter ( \x -> x =~ "^q" :: Bool ) . lines' Imports.hs [EMAIL PROTECTED]:~/learning/haskell/UnixTools$ cat Imports.hs import Text.Regex.Posix **************************** 2007/3/2, Thomas Hartman <[EMAIL PROTECTED]>: > Okay, I am aware of > > http://haskell.org/haskellwiki/Simple_unix_tools > > which gives some implementation of simple unix utilities in haskell. > > But I couldn't figure out how to use them directly from the shell, and > of course that's what most readers will probably wnat. > > Or let me put it another way. > > Is there a way to do > > find -maxdepth 1 -type f | xargs du | perl -ane 'print "\$F[0]\n"' | > perl -e '$sum += $_ while <>; print "$sum\n"' > > as a shell command that idiomatically uses haskell? > > For non-perlers, that sums up the disk usage of all files in the > current directory, skipping subdirs. > > print "\$F[0]\n > > looks at the first (space delimited) collumn of output. > > perl -e '$sum += $_ while <>; print "$sum\n"' > > , which is I guess the meat of the program, sums up all the numbers > spewed out of the first column, so in the end you get a total. > > So, anyone out there want to establish a haskell one liner tradition? > > :) > > thomas. >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe