If You use
bash You could try something like this, very simple and probably lots of pitfalls. But since You are processing source code there are syntactic rules that can be expected to be followed. It simply checks for
the Begin word and increments the file name index when encountered.
Code:
lakris@ubuntu:~/projekt/scripts$ cat projekt.txt
Begin Object1
txt1
end
;
Begin Object2
txt2
end
;
Begin Object3
txt3
end
;
Begin Object4
txt4
end
;
lakris@ubuntu:~/projekt/scripts$ cat splitit.sh
#!/bin/bash
cnt=0
while read line;do
[[ "$line" =~ "Begin" ]] && cnt=$(($cnt+1))
echo $line goes into Object$cnt.txt
done < projekt.txt
lakris@ubuntu:~/projekt/scripts$ ./splitit.sh
Begin Object1 goes into Object1.txt
txt1 goes into Object1.txt
end goes into Object1.txt
; goes into Object1.txt
Begin Object2 goes into Object2.txt
txt2 goes into Object2.txt
end goes into Object2.txt
; goes into Object2.txt
Begin Object3 goes into Object3.txt
txt3 goes into Object3.txt
end goes into Object3.txt
; goes into Object3.txt
Begin Object4 goes into Object4.txt
txt4 goes into Object4.txt
end goes into Object4.txt
; goes into Object4.txt
lakris@ubuntu:~/projekt/scripts$
Change "goes into" to ">>" when You are confident that the output is what You want. It will append to any file with that name so You may want to remove any Object*.txt first.
/Lakris