computer help index
 
 
Search:
"Offering free computer help, hints, and tips to the Internet populace." Now with over 3,490 tips!

Windows XP and DOS

GREP Command for Windows XP

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:

QGREP /?

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:

apple
apple tree
apple cider
apple juice
banana

Now, here are examples of a few QGREPs in action:

C:\temp>qgrep tree greptest.txt

Result:

apple tree

An example searching for lines matching one of the selected strings:

C:\temp>qgrep "juice cider" greptest.txt

Result:

apple cider
apple juice

An example searching for lines matching the exact phrase:

C:\temp>qgrep -E "apple cider" greptest.txt

Result:

apple cider

An example of the "-v" modifier that matches lines NOT containing the specified string:

C:\temp>qgrep -v apple greptest.txt

Result:

banana

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

Result:

apple cider

The brackets "[]" match characters in a range.

C:\temp>qgrep -X "[t-z]" greptest.txt

Result:

apple tree
apple juice

 

 
Add: Del.icio.us | Digg | Furl | My Yahoo!
 

Discuss This Tip

Print This Tip

Get E-Mail When New Tips are Online

Return to the Windows XP and DOS page.


More in MalekTips:
Google GmailWindows XP and the KeyboardSites to Browse - Music



Move the Chat or Labels Section to the RightPrevent the Cursor from BlinkingInternet Archive's Audio Archive

RSS Feeds - Subscribe!
 

You want the latest tech tips and tricks in your e-mail Inbox - FREE? Type your e-mail address below and click 'Subscribe'.
 



( sample / details ) ( opt-out instructions )
 


 Free Offer! - Subscribe to the MalekTips computer help list and be one of the first to get new computer tips, articles, and download links! ( privacy policy )  ( opt-out instructions )
This page and its contents are copyright
©1997 - 2008 Envision Programming. ( copyright/disclaimer )

Home | Free Computer Help Newsletter! | Windows | Web Development | DOS and Batch Files | Removing Spyware
Digital Camera and Photography | Computer and Internet | Software | Microsoft Word
Computer Articles | About | Contribute a Tip | Link To Us! | Computer and Technology Links
RSS Feeds |  Contact Us | Advertising | Privacy Policy | Computer Help Forums