Thursday, July 05, 2007

DOS 'grep' equivalent - the find command

The previous post talked about finding which ports were open using the netstat command.

But you still have to scan the output manually to find the port you are looking for.

In the Unix world you could simply use grep and pipe the output to it.

In the DOS world, you can use find.

help find

Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.

So to find if port 86 was open, use:

netstat -ano | find /i "86"

and the filtered output would something like:

UDP *:* 728



Anonymous said...

Thank you, this works great for finding strings in command output like net statistics.

grt Berto

ambar said...

Yeah, this was an awesome post. Really really useful for all command line users. Kudos!

Anonymous said...

Thanks! FIND command was just what I needed.

SMK said...

curious - why ignore the case of numbers?

but thanks for the find!