Tuesday, June 25, 2019

Row count with DOS "Find Command"

Windows find command :

Using ‘Find’ command,  we can search for specific text in a set of files. Find below the syntax of this command with examples. Note that windows find command is different from the Linux find command in functionality. Linux find command is used to search for files that match the given criteria. But the windows find command is useful to search files for the lines that match the given string. The windows command that matches partially with Linux find command’s functionality is dir command.

Syntax and Examples

Find the lines of a file that have the specified string
find "string" filename
Ex:

C:\>find "Windows" C:\boot.ini
---------- C:\BOOT.INI
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect


To print line numbers along with the lines
find /N "string" filename
Ex:

C:\>find /N "Windows" C:\boot.ini
---------- C:\BOOT.INI
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect



To ignore case in searching for the string, we can add /I switch.
find /I /N "string" filename
In the below example, we don’t find any matching lines when we search for ‘windows’. In the next command, I have added /I and it shows the matching line ignoring the case differences.

C:\>find /N "windows" C:\boot.ini

---------- C:\BOOT.INI

C:\>find /N /I "windows" C:\boot.ini

---------- C:\BOOT.INI
[3]default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect


To find the lines that are not matching with the given string:
We can use /V switch for this case. Please find the command syntax below.

find /V  "string" filename
Ex:

C:\>find /N "windows" C:\boot.ini
---------- C:\BOOT.INI

C:\>find /N /I "windows" C:\boot.ini

---------- C:\BOOT.INI
[3]default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[5]multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect




Reference Site


No comments:

Post a Comment

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.Please don't spam,spam comments will be deleted upon reviews.