
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.)
**************
thartman@linodewhyou:~/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
thartman@linodewhyou:~/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
thartman@linodewhyou:~/learning/haskell/UnixTools$ cat Imports.hs
import Text.Regex.Posix
****************************
2007/3/2, Thomas Hartman
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.