-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a switch to Select-String that returns the matching parts only, analogous to grep -o #7712
Comments
@SteveL-MSFT Can you approve? |
I think this should works for |
@PowerShell/powershell-committee reviewed this, seems fine to add but should match the grep description of the parameter and call it |
The OnlyMatching name doesn't correlate with "output" 😕 |
Seems like a lot of the time, that's all I want 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 😃 Yay! |
@HumanEquivalentUnit, I quite like the idea of a |
@mklement0 I did; #7958 but it looked like a duplicate at the time, of your linked issue which is basically the same request. |
Oops! Completely forgot about #7867's |
@SteveL-MSFT There's one remaining design question to answer:
If we follow this logic, However, it may make more sense to have |
It is related to question about SimpleMatch + AllMatches. |
Yes: here we don't strictly have a backward-compatibility problem, because Technically we are therefore free to to support combining However, given the committee decision not to fix #11102 in order to support combining |
/cc @SteveL-MSFT |
I believe we could have an symmetry and PowerShell Committee could discuss both cases:
|
If someone curious about a current way of doing so, you can use this:
|
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? |
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. |
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. |
1 similar comment
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. |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
Related: #7713 and #7867
Sometimes all you want
Select-String
to do is to output only the matching parts of the input lines as strings, similar to whatgrep -o
does on Unix-like platforms; e.g.: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:As an alias,
-om
could be considered (just-o
could 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:
The text was updated successfully, but these errors were encountered: