1

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

  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?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Evan
  • 1,477
  • 1
  • 17
  • 34
  • 1
    Do you want lines 1..1000 in one file, and 1001..2000 in another, and so on, or do you want just lines 1000..2000 in another file? Both are doable (easily doable), but you do it differently (`sed` vs `split`). Also, do you need to preserve the heading line in each output file? – Jonathan Leffler Feb 15 '16 at 01:33
  • Classic case of the question title being different from the actual question. XY problem. – paddy Feb 15 '16 at 01:34
  • @Joanthan Leffler, 1..1000 in one file. 1001...2000 in another. I just made the title because if someone answered that. I could go from there and answer my own problem – Evan Feb 15 '16 at 01:40
  • Have you put any effort into trying to solve this yourself? If so, please indicate what you have tried. Lack of demonstrated effort on your part makes it likely that this question will be down-voted and closed. – EJK Feb 15 '16 at 01:57

1 Answers1

7

This sounds like a case for the POSIX split command:

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, ...

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278