Monday, January 12, 2009

If anyone were to ever need to take a text file full of lines and break it into sequentially numbered sections of 20 lines per section, here is how to do it:

use vi (in Windows, you better have cygwin...)

open the file in vi
hit : to bring up the command line at the bottom and paste this in:

%s/\v(.*\n){20}/&\rGroupnum\r

This is not perfect, you have to now edit it a bit, just move the "Groupnum" from the last line to before the first line and it should be OK.

then, to replace the string with the number, paste this into the command line:

let i=1 | g/Groupnum/s/Groupnum/\=i/ |let i=i+1

Magic.