Re: More Mac Ghost
Re: More Mac Ghost
- Subject: Re: More Mac Ghost
- From: "Arthur J Knapp" <email@hidden>
- Date: Wed, 22 Nov 2000 13:18:48 -0500
>
Date: Wed, 22 Nov 2000 13:47:10 +1030
>
Subject: More Mac Ghost
>
From: Phil APHS <email@hidden>
>
I have a file that goes like this:
>
|Business01 00:50:E4:1E:0E:15|
>
|Business02 00:50:E4:1E:1C:6F|
>
|Business03 00:50:E4:AE:0E:3D|
>
|Business04 00:50:E4:CE:22:4F|
>
|Business05 00:50:E4:1E:E4:3E|
>
I need applescript to read the file and search for a string (the Ethernet
>
address) and return the name of the machine as the result (I may have to
>
reverse it eg. first the Ethernet address then the name if it would be
>
easier) the Ethernet address is separated from the name with a tab.
The biggest question involved with reading files is the size of the
file. If you have enough memory to read the entire file into memory,
then this is a normal string-parsing question:
set file_string to read file "yada"
-- case sensitive
--
set text item delimiters of AppleScript to "00:50:E4:AE:0E:3D"
set file_string to text items of file_string
if length of file_string = 1 then
-- Ethernet address was not found
else
return word -1 of item 1 of file_string
end
-- case-insensitive
--
if file_string contains "00:50:E4:AE:0E:3D" then
repeat with x from 1 to (count of paragraphs in file_string)
if paragraph x of file_string contains "00:50:E4:AE:0E:3D" then
return word 1 of paragraph x
end
end
else
-- Ethernet address was not found
end
If the file is very large, then you need to read in *batches*
of lines, perform the same tests as above, and then read
in the next batch if the first batch failed.
--
{
Arthur J Knapp, of STELLARViSIONs ;
http://www.STELLARViSIONs.com ;
mailto:email@hidden ;
"...well the rain falls down
without my help, I'm afraid
and my lawn gets wet,
though I withheld my consent..."
}