Equivalent of UNIX Grep command in Dos/Windows
Categories: Operating System
You can use the ‘type’ and ‘find’ command in Dos/Windows to get the equivalent output of the UNIX ‘cat’ and ‘grep’ commands. The ‘find’ command can be very useful when you are trying to search for a specific text or phrase over multiple files. The ‘find’ command also comes in handy when searching for all the occurrences of a specific text or phrase in all the files under all the sub-directories of a given directory.
The Type Command
The ‘type’ command in Dos simply displays the contents of a text file or files. To see the content of a file simply enter the following in the command prompt:
C:>type “filename”
The Find Command
The ‘find’ command in Dos can be used to search for a text string in a file or files. below is the usage and optional parameters of the ‘find’ command.
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.
[drive:][path]filename
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.
Find Command Usage Examples
To find any text occurrence in all the files within a directory simply enter the following at the command prompt.
C:>find “text to find” *
D:\Project Material\find command example>find "text-align" *
---------- ADSENSE INSERTION TAG.TXT
<p style="text-align: center;"><!-- wp_ad_camp_1 --></p>
---------- CFORMS.PHP
echo '<p style="text-align: left;"><label for="cforms-title'.$no.'">';
---------- ROBOTS.TXT
---------- ROBOTS_LANGUAGE_FILTER.TXT
---------- TRANSLATION_PAGE.TXT
Use the ‘/n’ parameter to print out the line numbers.
D:\Project Material\find command example>find /n "text-align" *
---------- ADSENSE INSERTION TAG.TXT
[1]<p style="text-align: center;"><!-- wp_ad_camp_1 --></p>
[2]text-align
[3]Test line with the text text-align
[6]Another line with the desired text text-align
---------- CFORMS.PHP
[2269] echo '<p style="text-align: left;"><label for="cforms-title'.$no.'">';
---------- ROBOTS.TXT
You can use ‘type’ and then pipe the output to the ‘find’ command:
D:\Project Material\find command example>type robots.txt | find /n "Disallow: /iw/"
[37]Disallow: /iw/
You can get really creative with these commands.
Tags: dos command, UNIX, Windows









#1 by Cindy z on July 2, 2010 - 10:13 am
THANKS for sharing! I used to use grep and cat on unix which came in very handy. now the find and type commands will be very handy as well. THANKS!!!!
#2 by Danish on August 5, 2010 - 4:25 pm
Thank you for sharing the info.
Indeed Find is grep like but alas not grep
with grep, tr, cut it seems. If only Mic had given a little bit of attention to another side of the user interface- one as powerful as the command line. It would have the support of majority of the programmers.
#3 by Icechen1 on August 21, 2010 - 4:04 pm
Hehe, thanks for the share! As a old unix user, this can come in handy! Bookmarked.
Icechen1´s last blog ..Facebook Places released- time to tighten up privacy settings