I create a simple understable function that you can use with large files:
function Get-Content-Since-Equals-To-File(){
param (
[string] $Path,
[string] $LineText,
[string] $PathNewFile
)
$writer = [System.IO.StreamWriter]::new($PathNewFile)
$continue=0
foreach($line in [System.IO.File]::ReadLines($Path))
{
if($line.Equals($LineText)){$continue=1}
if( $continue -eq 1){
#Add-Content -Path $PathNewFile -Value $line #According to mklement0 using Add-Content is really slow
$writer.WriteLine($line);
}
}
$writer.Dispose();
}
Then you can invoke that function by just pass the file path , the word since you want to get the file and the new file Path:
Get-Content-Since-Equals-To-File -Path ./1.txt "Jaguar" -PathNewFile './newFile.txt'
The above result produce a file with the desired result(note I'm using relative paths as an example, in your day-to-day you should use absolute paths and consider the working dir aka cwd):
Get-Content ./newFile.txt
Jaguar
Frog
Snake
This function is based on Read file line by line in PowerShell , because it reads line by line you can use it in large files.
In case you don't need to match you can use other conditions to adapt the function.
Thanks to @mkelement0 for the improvement on Add-Content, I updated the code by using a StreamWriter.