As far as I know, this should be portable to Win32. Unless grep isn't implemented there, but I believe it to be. If you let me know where this fails on Win32, I might be able to help.
Also, wog's solution below looks like it will handle any portability issues transparently.