Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

helpcasey

macrumors newbie
Original poster
Nov 21, 2008
3
0
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

macrumors 65816
Jul 29, 2005
1,482
18
Don't step into the kawoosh...
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

macrumors newbie
Original poster
Nov 21, 2008
3
0
*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

macrumors 65816
Jul 17, 2008
1,334
4
Maryland
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

macrumors newbie
Original poster
Nov 21, 2008
3
0
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.