Techno World Inc - The Best Technical Encyclopedia Online!

THE TECHNO CLUB [ TECHNOWORLDINC.COM ] => Others => Topic started by: Mark David on March 16, 2007, 12:43:39 PM



Title: msh: Extract text from a stream with grep-string
Post by: Mark David on March 16, 2007, 12:43:39 PM
msh: Extract text from a stream with grep-string

One of the biggest missing functions in the command prompt is the ability to extract lines from a file that match a pattern. For UNIX users, the command grep is so often used that it has become a verb. The msh has a grep-string cmdlet that performs grep-like string parsing.

Use grep-string to search for a text pattern in a stream of text, for example:

Code:
dir | grep-string txt

will extract lines from the dir command output containing the text txt. For more information about the use of grep-string, use the help cmdlet:

Code:
help grep-string

Unfortunately, it appears that Microsoft used the name grep without really meaning it. Grep stands for global regular expression parser and its greatest strength is the 'regular expression' part. The msh grep-string doesn't use regular expressions. One promising thought is that since these are all defined cmdlets, someone adventurous could write a real grep function.