Hello–
I am an extreme n00b to Applescript, and though I have been struggling through tutorials here and there, I’m now a bit stumped. Here’s my situation:
I am running experiments for a linguistics lab, using the TCL/TK program Linger. This is insubstantial to the question at hand, but it gives a general idea of the scope. Anyhow, for each participant, the program outputs a .dat file with the subject number, the name of the experiment, the sentence number, the condition (for this experiment, it’s “obj” for every one), a percentage sign, their rating of this particular question on a scale of 1-7, and the time it took them to answer. Here’s a sample:
1 similarity 62 obj 0 - - 1886884
1 similarity 62 obj % 2 {} 1689426
The first one above was the reading screen, which did not have a rating associated with it. Every other screen is a reading screen. The first two entries thus look like this:
1 similarity 62 obj 0 - - 1886884
1 similarity 62 obj % 2 {} 1689426
1 similarity 38 obj 0 - - 414750
1 similarity 38 obj % 6 {} 1164866
This is just to let you know there will be some “junk processing” that needs to go on.
Anyhow, for this particular experiment, I need to put this data into an excel 2008 spreadsheet, ordered by the sentence number. So for the above input, all I want in excel is:
38 6
62 2
I have been able to do this so far with the regular expression [0-9] similarity ([0-9]+) obj % ([0-9]) .* , which is replaced with $1 $2. I also run a regular expression to get rid of the junk data and replace it with a blank space. This allows me to open the file in excel and import the data, whereupon I can sort by sentence number manually.
Given that there will be quite a few subjects, however, I want to be able to do this via Applescript. Each subject has his/her own .dat file, and all of them are similarly formatted. Namely, I want to be able to open each .dat file, parse it correctly to get sentence number and rating for all sentences, and put it, sorted, into an excel worksheet.
Ideally, I would have each sentence number corresponding to row number, and columns corresponding to participant number. I would fill the data in with the rating that each participant gave to the given sentence.
This seems like a specific question, but much more generally, it deals with parsing a text file via applescript and putting it into an excel worksheet in the right format. I believe this question can benefit many people seeking to do similar excel processing with applescript (especially now that they disabled VB).
Any help you can give would be greatly appreciated!