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

后端 未结 5 1678
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 02:54

I have csv file and want to output a new csv file, that only contains the first 10 lines form the original one. I\'ve so far only found code to delete single lines or lines that

5条回答
  •  耶瑟儿~
    2021-01-31 03:08

    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.

提交回复
热议问题