(Sorry in advance for my bad english.)
I have 2 questions:
My code:
Select-String .\example.txt -pattern "myword" | select -ExpandProperty line
OK nice. PowerShell found the word within line 63. After line 63, the .txt file has x more lines, and all of (64) them should be deleted. How can this be done?
get-content .\example.txt | select-string -pattern 'myword' -notmatch | Out-File .\new_example.txt
This deleted only line 63. However, this should remain and only the rest should be deleted.
Example .txt file: 10a, 11a, 21a, 20w, 32a, 56a, 123a,
That is desired .txt file: 11a, 21a, 20w, 32a, 56a,
How can I make it? I hope so mutch that you can help me by this problems. Thanks.
Using the proposed prototype in #15136
Add -From
and -To
parameters to Select-String
:
@'
One
Two
myword
three
'@ -split '\r?\n' |SelectString -To myword
returns
One
Two
'10a', '11a', '21a', '20w', '32a', '56a', '123a' |
SelectString -From '(?=11a)' -To '(?<=56a)'
Returns
11a
21a
20w
32a
56a
See also: