One of the ways to get number of lines from a file is this method in PowerShell:
PS C:\\Users\\Pranav\\Desktop\\PS_Test_Scripts> $a=Get-Content .\\sub.ps1
Here is something I wrote to trying lessening the memory usage when parsing out the white-space in my txt file. With that said, the memory usage still get kind of high, but the process take less time to run.
Just to give you some background of my file, the file had over 2 millions records and have leading white space in both front and rear of the each line. I believe total time was 5+ minutes.
$testing = 'C:\Users\something\something\test3.txt'
$filecleanup = Get-ChildItem $testing
foreach ($file in $filecleanup)
{
$file1 = Get-Content $file -readcount 1000 | foreach{$_.Trim()}
$file1 > $filecleanup
}