Thursday, November 21, 2024
HomeComputer programmingWindows Monad mshmsh: Extract Text from a Stream with grep-string

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. Note the following example:

dir | grep-string txt

This 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:

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 does not use regular expressions. One promising thought is that since these are all defined cmdlets, someone adventurous could write a real grep function.

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!