I need to evaluate the lines in a file. Each line is made up of loan data like price, credit score, etc etc . I need to filter on these values and if selected write the line to an output file.
The problem is the file has 400,000 + lines.
Each line has about 20+ values to filter on,
And I cannot take more than 60 seconds for this part of the script.
Any ideas how i can make the code faster?
Here is the code:
$File_NotesDownload = "C:\temp\NotesDownload.csv"
$File_NotesGood = "C:\temp\NotesGood.txt"
if (Test-Path $File_NotesGood) { remove-item $File_NotesGood }
$Start = Get-Date
$Notes = Get-Content $File_NotesDownload
foreach($Note in $Notes)
{
$Note = $Note -replace '"',''
$Loan_Id = ($Note -split ',')[0].trim()
$Loan_Id = $Loan_Id -as [int]
if (($Loan_Id -is [int]) -eq $false) {Continue}
$Loan_Status = ($Note -split ',')[5].trim()
$Ask_price = ($Note -split ',')[6].trim()
$Markup_Discount = ($Note -split ',')[7].trim()
$YTM = ($Note -split ',')[8].trim()
$DaysSinceLastPayment = ($Note -split ',')[9].trim()
$CreditScoreTrend = ($Note -split ',')[10].trim()
$FicoEndRange = ($Note -split ',')[11].trim()
$NeverLate = ($Note -split ',')[13].trim()
$Loan_Class = ($Note -split ',')[14].trim()
$Loan_Maturity = ($Note -split ',')[15].trim()
$Interest_Rate = ($Note -split ',')[17].trim()
$RemainingPayments = ($Note -split ',')[18].trim()
if ($Loan_Maturity -ne 36) {Continue}
if (($Interest_Rate -lt 4) -Or ($Interest_Rate -gt 25)) {Continue}
if ($Ask_price -gt 20) {Continue}
if ($Markup_Discount -gt -0.01) {Continue}
if ($YTM -lt 10) {Continue}
if ($CredScoretrend -ne "UP") {Continue}
$NotesList += $Note + "`r`n"
}
$NotesList | out-file $File_NotesGood
$End = Get-Date
$TotalTime = New-Timespan -Start $Start -End $End
$TotalTimeSecs = $TotalTime.seconds
$TotalTimeSecs