Re: Read a text file ...
Re: Read a text file ...
- Subject: Re: Read a text file ...
- From: Emmanuel <email@hidden>
- Date: Sat, 19 Apr 2003 22:25:08 +0200
At 9:32 AM -0700 19/04/03, Charles Heizer wrote:
Hello,
I'm writing a small applescript to scp a couple of files to a list
of hosts. I have crated a text file that has the info I need, it
looks like this -
myfirsthost.example.com;user;password
host2.example.com;user;password
So the file is delimited by semicolons. So I've been reading the
archives and I can't seem to figure out how to fill in the variables
in my script with the contents of each line.
If you can use either the Satimage osax (a freeware) or the script
editor Smile (a freeware), then you can use a regular expression and
the solution to your question is a one-liner:
---------- (the file)
myfirsthost.example.com;user1;password1
host2.example.com;user2;password2
-------------------
-------------------
set theList to (find text "^([^;]+);([^;]+);([^;]+)$" in (read
theFile) using {"\\1", "\\2", "\\3"} with regexp, all occurrences and
string result)
-------------------
--> {{"myfirsthost.example.com", "user1", "password1"},
{"host2.example.com", "user2", "password2"}}
(Saturday regular expression lectures, lesson 1
hat = beginning of line, dollar = end of line, [^;] is any character
except semicolon, "+" means 1 occurrence or more)
Then you can write:
-------------------
set {theHost, theUser, thePass} to item 2 of theList
-------------------
or, in a loop:
-------------------
repeat with theInfo in theList
set {theHost, theUser, thePass} to theInfo
-- your script here
end repeat
-------------------
Emmanuel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.