mardi 30 novembre 2021

Powershell question - How can I deleted lines from a certain position?

(Sorry in advance for my bad english.)

I have 2 questions:

  1. Question: I have a .txt file and search with powershell for a word into the .txt:

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.

  1. Question: Almost the same. I search for two countings Example: 12 and 33 into the .txt Powershell found not 12a and 33a. That's right. Powershell should for it "11a until 56a", and clear line "10a" and "123a"

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.

Aucun commentaire:

Enregistrer un commentaire