SUMMARY: Search text files for matching strings with the GREP-like command for Windows XP and DOS.
The DOS command 'QGREP' offers a GREP-like command for Windows XP. With this command you can perform powerful standard and regular expression searches through text files, such as logging and debugging information, similar to what you can do with the UN*X GREP command. QGREP lets you search through one or a multiple of files.
(This command requires the Windows 2003 Resource Kit - if you do not have it, read the Windows 2003 Resource Kit download/install instructions.
Like the UN*X GREP command, the Windows XP QGREP command set is extensive; to see a full list of commands, enter the following at a DOS prompt:
Here is the command reference:
usage: qgrep [-?BELOXlnzvxy][-e string][-f file][-i file][strings][files]
-? - print this message
-B - match pattern if at beginning of line
-E - match pattern if at end of line
-L - treat search strings literally (fgrep)
-O - print seek offset before each matching line
-X - treat search strings as regular expressions (grep)
-l - print only file name if file contains match
-n - print line number before each matching line
-z - print matching lines in MSC error message format
-v - print only lines not containing a match
-x - print lines that match exactly (-BE)
-y - treat upper and lower case as equivalent
-e - treat next argument literally as a search string
-f - read search strings from file named by next argument (- = stdin)
-i - read file list from file named by next argument (- = stdin)
White space separates search strings unless the argument is prefixed with -e, e.g., 'qgrep "all out" x.y' means find either "all" or "out" in x.y, while 'qgrep -e "all out" x.y' means find "all out".
Let's see the command in action. First, create a text file GREPTEST.TXT with the following content:
Now, here are examples of a few QGREPs in action:
C:\temp>qgrep tree greptest.txt
An example searching for lines matching one of the selected strings:
C:\temp>qgrep "juice cider" greptest.txt
An example searching for lines matching the exact phrase:
C:\temp>qgrep -E "apple cider" greptest.txt
An example of the "-v" modifier that matches lines NOT containing the specified string:
C:\temp>qgrep -v apple greptest.txt
Some examples of regular expression searching, similar to what UN*X's GREP command can do:
The period "." matches any character.
C:\temp>qgrep -X "c.der" greptest.txt
The brackets "" match characters in a range.
C:\temp>qgrep -X "[t-z]" greptest.txt
Press the "print" button on your browser or select "File" - "Print" to print this tip. Then, return to Windows XP and DOS - GREP Command for Windows XP
Standard disclaimer applies - read http://malektips.com/disclaim.html