-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add a switch to Select-String that returns the matching parts only, analogous to grep -o #7712
Copy link
Copy link
Open
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionFirst-Time-IssueEasy issues first time contributors can work on to learn about this projectEasy issues first time contributors can work on to learn about this projectHacktoberfestPotential candidate to participate in HacktoberfestPotential candidate to participate in HacktoberfestIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Metadata
Metadata
Assignees
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionFirst-Time-IssueEasy issues first time contributors can work on to learn about this projectEasy issues first time contributors can work on to learn about this projectHacktoberfestPotential candidate to participate in HacktoberfestPotential candidate to participate in HacktoberfestIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Related: #7713 and #7867
Sometimes all you want
Select-Stringto do is to output only the matching parts of the input lines as strings, similar to whatgrep -odoes on Unix-like platforms; e.g.:The equivalent
Select-Stringsolution is currently cumbersome:If we introduced a switch named, say,
-MatchingPartOnly(name TBD, could have an alias of-o)-OnlyMatching(see decision below), the command could be simplified to:As an alias,
-omcould be considered (just-ocould break existing code that used it for-OutVariable).This would also speed up processing, because constructing
[Microsoft.PowerShell.Commands.MatchInfo]instances can be bypassed.Environment data
Written as of: