Printing "END" before a new loop in AWK

First off, I have been learning AWK by trial and error over the last week or so, and there are some gaps in my basic understanding of the language.

Here is my situation: I am coding and outputting results from an experiment I conducted in Psyscope, which has all been compiled into a master file. The AWK script reads through the results and outputs the encoded information into individual files for each subject that was run. This output looks like this:

#Filename: syll 36970.awk

seed syll36970 #Identifies subject
c677 #Response 1
01611221 #Information about condition
i675 #Response 2
01612121 #Information about condition

And that pattern continues. Each file is like this with its unique information. The only thing that is missing is I want AWK to print "END" at the end of each file. For some reason, it either sticks it in with the response information or at the very beginning.

If you want to help me, respond and I can send you a copy of my script.

Thank you!

As always when asking for help with data formatting, post samples of input and desired output, along with what in the input corresponds with what in the output.

As a guess because I'm, not sure exactly what is wanted:

awk '$1 == "seed" { if ( filename )  { print "END" > filename ;  close(filename)} ; filename = $2 ".out" } { print > filename } END { print "END" > filename }' 

I have been thinking about how to clarify, and due to a lack of familiarity I am struggling. My input is fairly complex:

PsyScope 1.2.5 PPC started: 11/07/07 12:35:10
Script file: FL 1024x768 v24 NEW NEW
Run on: Power Macintosh
Random Seed: 549174

RunNumber: 1
SubjectNumber: 14
SubjectName: 37492
Native Language: English
Do you speak this language regularly?: Yes

Input devices active: MOUSE KEY
Timing Device: Macintosh

440 Item2 TY 1 L UNR INCORRECT 1120 0
441 Item5 TY 1 R UNL INCORRECT 704 0
442 Item1 TY 1 L GOL CORRECT 577 0

This is the header and first 3 responses for one subject. Now picture a file with 20 subjects with 60 responses each, and it is one large txt file. My program reads through that file and prints out all this information in a a code that can be analyzed by another program very easily, in the format shown in my first post. I am finding it difficult to have awk print END each time it gets to a new subject entry at the end of the previous file (so it is actually at the end). This is just another bit of the code that needs to be there for the analysis.

Each subject is being saved to a new file by my awk script, so instead of one mondo file, in the end I have 20 files that are titled ("Syll"SubName".out"), where subject name is the variable that contains each subjects ID code. All of those individual files follow the format that I presented before.

Because I could not do it within my original script, performed this work around. I had my original script generate a list of all the subject codes in another output file, and then created another script to read from that file and append "END" to all the "Syll" output files.

This is the file I generate with the codes...
#List of Subject Codes
001: 37492
002: 36970
003: 37255
004: 36826
005: 37522
006: 37420
007: 37465
008: 37417
009: 36946
010: 37531

Here is my code for the script END.awk
# -- END.awk

{FS=":"}
{print "END" >> ("Syll" $2 ".out")}

And that actually does the trick. The only thing is that I am going to be giving this script back to my professor to use, and I want it to be as neat as possible, so if I can do this all in one script that would be awesome.

Alright, I hope this is all the information you need and more! I tried saving the subject code to a new field within the original input file, and letting it post there every loop, but it didnt work out as planned at all. Although I am learning the usefulness of awk through this project, I am definitely learning its weaknesses, so if I should be going about this with a different scripting language all together, please let me know!

THANK YOU FOR YOUR HELP!:b: