Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 21, 2008, 03:56 PM   #1
helpcasey
macrumors newbie
 
Join Date: Nov 2008
Applescript to copy past from multiple txt files

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
helpcasey is offline   0 Reply With Quote
Old Nov 21, 2008, 04:45 PM   #2
prostuff1
macrumors 65816
 
prostuff1's Avatar
 
Join Date: Jul 2005
Location: Don't step into the kawoosh...
Quote:
Originally Posted by helpcasey View Post
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.
__________________
Vista: It's the blond version of OS's; pretty and fun, just... not functional for everything
prostuff1 is offline   0 Reply With Quote
Old Nov 21, 2008, 06:44 PM   #3
helpcasey
Thread Starter
macrumors newbie
 
Join Date: Nov 2008
*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?
helpcasey is offline   0 Reply With Quote
Old Nov 21, 2008, 09:27 PM   #4
mysterytramp
macrumors 65816
 
mysterytramp's Avatar
 
Join Date: Jul 2008
Location: 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
__________________
What looks large from a distance, close up ain't never that big.
mysterytramp is offline   0 Reply With Quote
Old Nov 25, 2008, 09:38 PM   #5
helpcasey
Thread Starter
macrumors newbie
 
Join Date: Nov 2008
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
helpcasey is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Help in applescript; multiple data from 2 txt files to create image file LERsince1991 Mac Programming 9 Nov 17, 2011 06:52 AM
Applescript to copy highlighted folder name to iCal ToDo List inaka Mac Programming 0 Sep 15, 2011 07:38 PM
method to extract data from multiple csv files shaunb83 Mac Programming 1 Jun 8, 2010 08:14 PM
Help: cannot copy/paste from Safari to/from X11 haquae MacBook Pro 0 Oct 8, 2009 11:16 AM
How to copy clips from one imovie file to another masterjedi73 Mac Basics and Help 4 Nov 8, 2005 04:35 AM


All times are GMT -5. The time now is 01:29 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC