i need some guidance. i have hundreds of CSV files i need to work with–they have some bad data we have to manually clean up prior to an import–as we visually verify the bad data
first, i wanted to get all of the bad data into one file so i wouldnt have to sort and edit hundreds of them. working based on the “date” column, i got everything with an empty date or a bad date of “00-00-0000” copied into a new file with this:
$csvPath = "\\server\share\CSV Files" $outpath = "H:\Documents\Scripts\csv_admin_empty.csv" $colHeader = 'Date' Get-ChildItem $csvPath -Recurse -Include *.csv | ForEach-Object { import-csv $_.FullName | Where-Object {$_.$colHeader -eq '' -or $_.$colHeader -match "00-00-0000"}} | Export-Csv -Path $outpath -NoTypeInformation
second, i want to now remove all rows with bad date info from the existing CSV files–that way we wont import bad data/duplicates, and i can update the CSV file i just made with good data for import.
but…i am still learning powershell and cant get what i want. i have tried a few iterations of this but i get a blank file, or i get my file “updated” where every empty column looks like: ,“”, instead of just , /facepalm
so im looking for some guidance on how im processing this wrong. ive done some reading and found some examples but im not understanding something still. i dont think the -ne and -notmatch in this are matching correctly–if i import a single file with that pattern, then export it to a new file, it hasnt ignored the “” or “00-00-0000” rows like i want.
$csvPath = "H:\Documents\Scripts\csv" $outpath = "H:\Documents\Scripts" $colHeader = 'Date' Get-ChildItem $csvPath -Recurse -Include *.csv | ForEach-Object { import-csv $_.FullName | Where {$_.$colHeader -ne '' -or $_.$colHeader -notmatch "00-00-0000"} | Export-Csv $_.fullname -NoTypeInformation }
simplified sample CSV data
site,id,Date,Form Id,Doc ID,DOB,Pat Loc,FileType,apptla
DPL,1/26/2006, Records,100052,5,CRMI
DPL, Records,100052,5,CRMI
DPL,1/27/2006, Records,100006,5,CRMI
DPL,00-00-0000, Records,100028,5,CRMI
DPL,00-00-0000, Records,100028,5,CRMI
any help would be appreciated.
thanks
-dave