Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split text file into pieces 1

Status
Not open for further replies.

Dominal

Technical User
Mar 2, 2003
14
HK
We have a text file source.txt with unknown number of lines. In bourne shell, how to split it into several files with 300 lines each and named the files in the format source##.txt?

Thanks!
 
You can do it with split ( see than man pages)
split -l 300 source.txt
HTH Dickie Bird (:)-)))
 
Thanks! However, if use split, is it possible to make the output file in the format source01.txt, source02.txt...etc instead of sourceaa.txt, sourceab.txt...?

I tried the csplit but if I run "csplit -f source srouce.txt 300", the first file created source01 only contains 299 lines instead of 300 lines.
 
From the manual :
For example, if the original file had 108 lines and you entered:

csplit orginal.txt 11 72 98
the csplit command would create four files: the xx00 file would contain lines 1-10, the xx01 file would contain lines 11-71, the xx02 file would contain lines 72-97, the xx03 file would contain lines 98-108.


So - do csplit -f source source.txt 301
Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top