Extract only the first 10 lines of a csv file in powershell Extract only the first 10 lines of a csv file in powershell powershell powershell

Extract only the first 10 lines of a csv file in powershell


Get-Content "C:\start.csv" | select -First 10 | Out-File "C:\stop.csv"

That did it


Get-Content in.csv -Head 10 > out.csv


Using -TotalCount parameter is recommended. Especially, if you have a big CSV file.By this way, you will only read the first 10 lines of your CSV file instead of reading all lines, selecting the first 10 lines and extracting them.

Get-Content C:\Temp\Test.csv -TotalCount 3 | Out-File C:\Temp\Test10lines.csv

This works in Powershell 2 onwards.