-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Related: #7712
Sometimes, all you're interested in is the matching input lines as strings rather than full-blown [Microsoft.PowerShell.Commands.MatchInfo] instances.
Not having to extract the .Line property in subsequent processing can also significantly improve performance.
Update: Performance was originally discussed only with respect to how expensive wrapping the matched strings in MatchInfo instances is to begin with: nothing to worry about, apparently - see comments for a discussion.
A new switch named, say, -Bare switch could instruct Select-String to output (undecorated) strings only.
$res = 'line1', 'lineother', 'line3' | Select-String '\d' -Bare; $res; '---'; $res[0].GetType().Name
line1
line3
---
StringNote: I'm suggesting the somewhat abstract name -Bare, because the abstract logic of this proposal - namely to output "bare" objects that are undecorated (have no ETS properties added to them) / are not wrapped in instances of a helper type - applies to other cmdlets as well, such as in #7537, and its conceivable that other cmdlets may benefit from -Bare too, such as ConvertTo-Json in order to solve #5797; other cmdlets could benefit from such a switch too, such as Compare-Object.
Update: The case for -Bare as a general pattern has since been made in #7855.
Environment data
Written as of:
PowerShell Core 6.1.0-preview.4