You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a switch to Select-String that returns the matching parts only, analogous to grep -o #7712
Committee-ReviewedPS-Committee has reviewed this and made a decisionFirst-Time-IssueEasy issues first time contributors can work on to learn about this projectHacktoberfestPotential candidate to participate in HacktoberfestIssue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
Sometimes all you want Select-String to do is to output only the matching parts of the input lines as strings, similar to what grep -o does on Unix-like platforms; e.g.:
# Extract only the parts that match the regex, each on its own line.
PSonUnix>"line1`nline2`nline3"| grep -o '[0-9]'123
The equivalent Select-String solution 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:
Sometimes all you want Select-String to do is to output only the matching parts of the input lines as strings
Seems like a lot of the time, that's all I want -match to do as well; and this would get roughly as close as my imaginary -keep operator (the inverse of -replace):
PS C:\>'a word and here'|Select-String-AllMatches -MatchingPartOnly -Pattern'\w{4}'
word
here
PS C:\>'a word and here'| sls -a -m '\w{4}'
word
here
PS C:\>'a word and here'-keep '\w{4}'
word
here
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Committee-ReviewedPS-Committee has reviewed this and made a decisionFirst-Time-IssueEasy issues first time contributors can work on to learn about this projectHacktoberfestPotential candidate to participate in HacktoberfestIssue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
Activity
iSazonov commentedon Sep 6, 2018
Steve Lee (@SteveL-MSFT) Can you approve?
iSazonov commentedon Sep 6, 2018
I think this should works for
-SimpleMatchtoo.SteveL-MSFT commentedon Nov 7, 2018
@PowerShell/powershell-committee reviewed this, seems fine to add but should match the grep description of the parameter and call it
-OnlyMatchingiSazonov commentedon Nov 8, 2018
The OnlyMatching name doesn't correlate with "output" 😕
HumanEquivalentUnit commentedon Mar 27, 2019
Seems like a lot of the time, that's all I want
-matchto do as well; and this would get roughly as close as my imaginary-keepoperator (the inverse of-replace):😃 Yay!
mklement0 commentedon Mar 27, 2019
HumanEquivalentUnit, I quite like the idea of a
-keep(or perhaps-extract) operator . Can I suggest you create a feature request for it?HumanEquivalentUnit commentedon Mar 27, 2019
Michael Klement (@mklement0) I did; #7958 but it looked like a duplicate at the time, of your linked issue which is basically the same request.
5 remaining items
iSazonov commentedon May 28, 2020
I believe we could have an symmetry and PowerShell Committee could discuss both cases:
vazome commentedon Aug 8, 2020
If someone curious about a current way of doing so, you can use this:
Kissaki commentedon Oct 16, 2021
This issue is labeled Up-for-Grabs but PR #10696 seems to tackle it? If so, wouldn't it be adequate to remove the up for grabs label?
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.