0
$result = Get-Content -Path D:\out.txt  
$grepString = $result | Select-String -Pattern "startpoint of the string"    
Write-Host $grepString

I used this code but it is printing only one line(when it get \n), But I want my output in containing rest of the lines

5
  • So you want the text as of a string "startpoint of the string", all the way to the end? Is that including "startpoint of the string" ? Commented Mar 17, 2021 at 12:47
  • Could you please provide out.txt file text and expected output? Commented Mar 17, 2021 at 13:00
  • yes it prints only one line from the starting point and then terminates what to do for getting output to the end of the file Commented Mar 17, 2021 at 19:20
  • I see there is no option to provide the out.txt file how i can send you that file please tell if you know Commented Mar 17, 2021 at 19:21
  • add the 1st few lines of the text of the Out.txt file to your Question. Commented Mar 18, 2021 at 1:03

1 Answer 1

1

You could use the .Where() extension method in SkipUntil mode:

$result = Get-Content -Path D:\out.txt  
$filteredResults = $result.Where({$_ -match "startpoint of the string"}, 'SkipUntil')

$filteredResults is now an list of the input strings from the first match till the end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.