如何在Bash中的每个块中将文件拆分为1000行的块? [重复]

时间:2022-07-22 21:33:02

This question already has an answer here:

这个问题在这里已有答案:

I have a file that is 6200 lines long that looks like:

我有一个6200行长的文件,看起来像:

  chrom chromStart chromEnd score           a          a.1
1  chr1     834359   867552     4 0.020979021 0.0000000000
2  chr1    1880283  1940830     9 0.075757576 0.0000000000
3  chr1    1960387  2064958    13 0.115093240 0.0006596306
4  chr1    2206040  2249092     5 0.019230769 0.0000000000
5  chr1    2325759  2408930    11 0.021296885 0.0080355001

I need to break the file into files that are 1000 lines long. How can this be done?

我需要将文件分成1000行长的文件。如何才能做到这一点?

1 个解决方案

#1


1  

This sounds like a case for the POSIX split command:

这听起来像POSIX split命令的情况:

split -l 1000 file-to-be-split prefix.

This will split the 'file to be split' into files with 1000 lines each (except the last, of course), and the names will start with prefix. and will end with aa, ab, ac, ...

这会将“要拆分的文件”拆分为每行1000行的文件(当然除了最后一行),名称将以前缀开头。并以aa,ab,ac,...结束

#1


1  

This sounds like a case for the POSIX split command:

这听起来像POSIX split命令的情况:

split -l 1000 file-to-be-split prefix.

This will split the 'file to be split' into files with 1000 lines each (except the last, of course), and the names will start with prefix. and will end with aa, ab, ac, ...

这会将“要拆分的文件”拆分为每行1000行的文件(当然除了最后一行),名称将以前缀开头。并以aa,ab,ac,...结束