英文:
How would one copy only the first x lines of a *csv* file into a new *csv* file via the cmd in windows
问题
head -N file.csv > newfile.csv
这是适用于Mac OS终端的解决方案,请问是否需要Windows cmd
上的相同操作?
英文:
How would one copy only the first x
number lines of a csv
file into a new csv
file via the cmd
on Windows?
head -N file.csv > newfile.csv
this is the solution for Mac OS terminal, can someone please tell the same for windows cmd
?
答案1
得分: 1
If you REALLY want to do it via batch there are several methods for doing it here https://serverfault.com/questions/490841/how-to-display-the-first-n-lines-of-a-command-output-in-windows-the-equivalent
Or the way I used to do it back in the days before Powershell was via the GNU port of the *nix Head
command which can be downloaded from https://gnuwin32.sourceforge.net/packages/coreutils.htm
with which you'd extract the first (say 10) lines of text using
Head -n 10 file.csv > newfile.csv
But the easier native way IMHO is to just doing it using Powershell. In which case
Import-Csv -Path c:\folder\file.csv -Delimiter "," |
Select -First 10 |
Export-Csv -Path C:\folder\newfile.csv -NoTypeInformation
would do what you need.
英文:
If you REALLY want to do it via batch there are several methods for doing it here https://serverfault.com/questions/490841/how-to-display-the-first-n-lines-of-a-command-output-in-windows-the-equivalent
Or the way I used to do it back in the days before Powershell was via the GNU port of the *nix Head
command which can be downloaded from https://gnuwin32.sourceforge.net/packages/coreutils.htm
with which you'd extract the first (say 10) lines of text using
Head -n 10 file.csv > newfile.csv
But the easier native way IMHO is to just doing it using Powershell. In which case
Import-Csv -Path c:\folder\file.csv -Delimiter "," |
Select -First 10 |
Export-Csv -Path C:\folder\newfile.csv -NoTypeInformation
would do what you need.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论