PDA

View Full Version : Applescript to copy past from multiple txt files




helpcasey
Nov 21, 2008, 03:56 PM
I would like to create a script file that will copy data from only certain sections of txt files and paste the data in a specific way into a new .txt file.

the set up for the data I would like to copy from each text file is
the file name
a string that is the first 8 characters of the 5th line of the file
a string that is the first 8 characters from the 9th line
a string that is the first 8 characters from the 13th line
a string that is the first 8 characters from the 17th line

I need this information to be pasted into the new document as shown below
_first line of txt file_
(filename from 1st file) (tab) (data from 5th line) (tab) (data from 9th line) (tab) (data from 13th line) (tab) (data from 17th line)
_second line of txt file_
((filename from 2st file) (tab) (data from 5th line) (tab) (data from 9th line) (tab) (data from 13th line) (tab) (data from 17th line)
_third line of txt file_
((filename from 3st file) (tab) (data from 5th line) (tab) (data from 9th line) (tab) (data from 13th line) (tab) (data from 17th line)

etc until all files in the folder have been run through.

I am sure there is a really easy way to do this, I am just having trouble finding all the calls for this. It may be easier to do it in a shell also.

Can anyone help me?

Casey



prostuff1
Nov 21, 2008, 04:45 PM
I would like to create a script file that will copy data from only certain sections of txt files and paste the data in a specific way into a new .txt file.

the set up for the data I would like to copy from each text file is
the file name
a string that is the first 8 characters of the 5th line of the file
a string that is the first 8 characters from the 9th line
a string that is the first 8 characters from the 13th line
a string that is the first 8 characters from the 17th line

I need this information to be pasted into the new document as shown below
_first line of txt file_
(filename from 1st file) (tab) (data from 5th line) (tab) (data from 9th line) (tab) (data from 13th line) (tab) (data from 17th line)
_second line of txt file_
((filename from 2st file) (tab) (data from 5th line) (tab) (data from 9th line) (tab) (data from 13th line) (tab) (data from 17th line)
_third line of txt file_
((filename from 3st file) (tab) (data from 5th line) (tab) (data from 9th line) (tab) (data from 13th line) (tab) (data from 17th line)

etc until all files in the folder have been run through.

I am sure there is a really easy way to do this, I am just having trouble finding all the calls for this. It may be easier to do it in a shell also.

Can anyone help me?

Casey

Do you have an example text file that you can post?

I can try to get something together when i get a chance but i can't promise anything.

helpcasey
Nov 21, 2008, 06:44 PM
*The title of this file is 0000.txt
the contents of the file is: *
(title "Volume fraction (solids) ")
(labels "Position" "Volume fraction (solids) ")

((xy/key/label "volume-fraction-26")
0.145203 0.02
)

((xy/key/label "volume-fraction-1e-1")
0.146001 0.1
)

((xy/key/label "volume-fraction-3e-1")
0.147857 0.3
)

((xy/key/label "volume-fraction-5e-1")
0.149679 0.5
)

** so for this txt file the line in the document I am looking for would be

0000 0.145203 0.146001 0.147857 0.149679

Any ideas?

mysterytramp
Nov 21, 2008, 09:27 PM
You probably don't want to copy and paste. Better to open the file and then set variables to the text you want:

set var1 to characters 1 thru 8 of paragraph 5 of document 1

etc.

Then build your output by concatenating your strings.

var1 & tab & etc.

Different editors might work better. For example, TextEdit will probably make "characters 1 through 8" into a list, which will then have to be reconverted into a string. You won't see it but it might slow down your script.

If you use Tex-Edit Plus, you can say:

set var1 to text 1 thru 8 of paragraph 5 of document 1

which should go faster, especially if this is in a loop.

mt

helpcasey
Nov 25, 2008, 09:38 PM
Thanks MT. Ill give that a try.. I really appreciate the help. Im very new to apple script so it may take me a while to implement this.

Casey