Com o GNU awk
:
BEGIN { fname = "/dev/null" }
/<header>/,/<\/header>/ { hdr = hdr $0 "\n"; next }
/^<event / {
events++
if(events % 10000 == 1) {
if(files++) close(fname)
fname = sprintf("file%02d.txt", files)
print hdr >fname
}
}
{ print >>fname }
Para executá-lo: grave-o em um arquivo script.awk
e execute:
gawk -f script.awk file.txt