I need to search a string in a file, and it show me the string and their x lineas before/after string, I tryed several sintaxis but I don´t know how do it. Could someone help me?
Example:
Get-Content -Path C:\Mi-log.txt | where { $_ -match "text-I-want-to-search" } -tail 5
Search string with Get-Content and show x lines before/after result
-
- Posts: 2
- Joined: 2021-Jul-27, 7:57 am
Re: Search string with Get-Content and show x lines before/after result
Select-String may solve your problem.
An example;
Ref: https://ss64.com/ps/select-string.html
Ref: https://www.jpsoft.com/forums/threads/s ... text.8773/
Joe
An example;
Code: Select all
powershell -command "$f = type c:\utils\astronomy.txt | Select-String -Pattern 'Sun in London - Next 7 Days' -context 0,11; $f"
Ref: https://www.jpsoft.com/forums/threads/s ... text.8773/
Joe