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!