Chrissy LeMaire has written some great articles on processing large CSV files.
You can modify her script to do other stuff with the data, you don’t have to upload to a SQL server.
My modified example below just outputs matches in column3 when comparing to a list of data in a text file - similar to what you want to do.
I used the All Countries text file (1.2GB and 10 million+ rows) linked in her article with a random list of 23 countries in my lookup file. It took just under 11 minutes to process 12 million rows.
$elapsed = [System.Diagnostics.Stopwatch]::StartNew()
$lookups = Get-Content 'E:\Temp\lookup.txt'
# CSV variables
$csvFile = 'E:\Temp\allcountries.txt'
$csvDelimiter = "`t"
$firstRowColumnNames = $false
$batchSize = 50000
# Create the datatable, and autogenerate the columns.
$datatable = New-Object System.Data.DataTable
# Open the text file from disk
$sr = New-Object System.IO.StreamReader($csvFile)
$columns = (Get-Content $csvfile -First 1).Split($csvdelimiter)
if ($firstRowColumnNames -eq $true) {
$null = $reader.readLine()
}
foreach ($column in $columns) {
$null = $datatable.Columns.Add()
}
# Read in the data, line by line
while (($line = $sr.ReadLine()) -ne $null) {
$i++
$null = $datatable.Rows.Add($line.Split($csvdelimiter))
if (($i % $batchSize -eq 0)) {
Write-Output $datatable.where({$_.column3 -in $lookups}).column3
Write-Host "$i rows have been processed in $($elapsed.Elapsed.ToString())."
$datatable.clear()
}
}
# Add in all the remaining rows since the last clear
if($datatable.Rows.Count -gt 0) {
Write-Output $datatable.where({$_.column3 -in $lookups}).column3
$datatable.Clear()
}
$sr.Close()
Write-Host "$i rows processed."
Write-Host "Total Elapsed Time: $($elapsed.Elapsed.ToString())"
You can modify the data in the data table directly if you want and then export it to CSV.
There are some examples here although unfortunately some of the example images are missing: