Windows has grep now too - where will it end?



A few weeks ago i posted my somewhat surprising discovery of a /dev/null for windows, as I've been having to do more work on windows recently i've also had cause to try and use command line pattern matching (i.e. look for a certain string in something).

I've known for a while there are extra tools you can install to let you do this - resource kits, cygwin and the like but it turns out there is actually a native command in the DOS shell that yet again has escaped me - when this appeared i don't know but i get the impression it's been around for years and yet again it's passed me by - maybe i need to pull myself away from a putty terminal once in a while....

anyway the command is called findstr

findstr /? will show you all it can do - but it has quite a lot of functionality and is actually a pleasant surprise to discover

for example to search for the string 143 in a netstat output (looking for sql server ports here) i can simply do this:

c:\> netstat -an |findstr 143
  TCP    0.0.0.0:1433           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:1435           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:1436           0.0.0.0:0              LISTENING
  UDP    0.0.0.0:1434           *:*

Simple eh and available natively - a useful tool when running oracle on windows - i'm sure i'll find out now that everyone who runs oracle on windows has known about this for years.....

1 comments:

  1. If you were hardcode, you would use MobaXterm and use standard UNIX commands on Windows. :)

    ReplyDelete