Powershell Script to remove rows from a CSV

Hi all.
I would like a script to remove all lines\rows from a .CSV log where an entry of "0" is found in the 3rd column. The csv does not have headers.
Does anyone know how I can do this using powershell?

Thanks very much.
jamiegfAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
You need to add as many "ColX" to the Header argument of Import-Csv as the file has columns; the scripts below assume 3.
If you want/need the fields enclosed in double quotes:
Import-Csv -Path C:\Temp\input.csv -Header Col1, Col2, Col3 |
	Where-Object {$_.Col3 -ne '0'} |
	ConvertTo-Csv -NoTypeInformation |
	Select-Object -Skip 1 |
	Set-Content -Path C:\Temp\output.csv

Open in new window

Without quotes:
Import-Csv -Path C:\Temp\input.csv -Header Col1, Col2, Col3 |
	Where-Object {$_.Col3 -ne '0'} |
	ConvertTo-Csv -NoTypeInformation |
	Select-Object -Skip 1 |
	ForEach-Object {$_.Replace('"', '')} |
	Set-Content -Path C:\Temp\output.csv

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jamiegfAuthor Commented:
You absolute legend! thanks very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.