-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
See also: #11752
Summary of the new feature/enhancement
Select-Object -Index allows me to select a subset of the input objects by an array of indices (0-based positions in the input stream):
PS> 1..5 | Select-Object -Index 1, 3 # here the same as: (1..5)[1,3]
2
4It would be helpful to be able to select the complement, i.e. all elements other than the ones specified, using a new -NotIndex parameter:
Update: The original proposal suggested a separate -Not switch to be combined with -Index, but this was changed based on @jhoneill's suggestion.
# WISHFUL THINKING: -Not returns everything *but* the objects at the specified positions.
PS> 1..5 | Select-Object -NotIndex 1, 3
1
3
5For instance, it would allow you to exclude a line with a given number from an array of a file's input lines:
# WISHFUL THINKING
PS> 1..3 + 'exclude me' + 4..5 > sample.txt; Get-Content sample.txt | Select-Object -NotIndex 3
1
2
3
4
5Note: While it is hypothetically possible to allow combining -Index with -NotIndex, it wouldn't be easy to reason about by the user and is probably of little practical value.
Thus, -Index and -NotIndex should be made mutually exclusive.