1
2
I am looking for a tool or script (Textwrangler or Terminal) that can split a larger text file every 100 lines counting from line 5 (the first 4 are header lines) and output individual .txt files which include the original header.
For instance
input:
File.txt
line1 / line4 HEADER
...
line5 / line265 DATA
output:
File_01.txt
line1/line4 HEADER
line5/line104 DATA
File_02.txt
line1/line4 HEADER
line5/line104 DATA
File_03.txt
line1/line4 HEADER
line5/line65 DATA
The text file uses Windows line breaks (CR LF) in case that matters.
I am currently doing this manually so any suggestions that can make this process more efficient are very welcome.
thanks! I had to substitute "--lines=100" for "-l 100" but apart from that it works like a charm. However ideally I would prefer a script or a single line command to do the job so it is easier for (less computer savvy) coworkers to take over these tasks in my absence. – Dan – 2010-09-14T11:49:33.990
@Dan - You could put it all in a script with a bit of fiddling. See my edit to automate the first part. – Nifle – 2010-09-14T13:17:51.413
I managed to compile your suggestions into a script. I also defined a few variables to incorporate the original file name in the output. It probably contains a few scripting faux pas since I am fairly new to this but it does the trick quite nicely. Thanks again! – Dan – 2010-09-15T12:44:10.683