[英]Extracting 200 lines from all the files in a folder
I have a folder with a lot of CSV files.我有一个包含很多 CSV 文件的文件夹。 There are subfolders also.
还有子文件夹。 For each such file I need to extract the first 200 lines (to make a db sub sample) creating another file with these lines.
对于每个这样的文件,我需要提取前 200 行(以制作 db 子样本),用这些行创建另一个文件。 So I would have several new files with 200 lines within each of them.
所以我会有几个新文件,每个文件都有 200 行。 I need to complete this task in Linux Ubuntu and using OS shell commands.
我需要在 Linux Ubuntu 并使用 OS shell 命令完成此任务。 Is there a way to do this?
有没有办法做到这一点? Thanks in advance.
提前致谢。
This line could respond to your need:此行可以满足您的需求:
find . -type f -name "*.csv" -print|xargs -I@ sh -c 'head -n200 @ > @.headed'
This line is made with different part:这条线由不同的部分组成:
With this line you have a solution that could be extensible for another usecase near the one you've written.有了这一行,您就有了一个解决方案,该解决方案可以扩展到您编写的那个附近的另一个用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.