Re: Search a file question - Mac OS 9
Re: Search a file question - Mac OS 9
- Subject: Re: Search a file question - Mac OS 9
- From: "Arthur J. Knapp" <email@hidden>
- Date: Tue, 17 Sep 2002 16:55:19 -0400
>
Date: Tue, 17 Sep 2002 10:24:46 -0700
>
Subject: Search a file question - Mac OS 9
>
From: Charles Heizer <email@hidden>
>
I'm having some trouble getting a script to read a log file to work
>
properly.
>
I'm trying to find any line that that contains "RC [someerror]" for
>
example. Then write that line with it's line number out to a new text
>
file. The thing is I don't want it to grab the lines that contain "RC
>
[0]" because a return code of zero means there were no problems.
Charles, is this a fairly small log file, somewhere under 32k? If it
is, we can really do all of our work as basic string manipulations:
set log_content to read (choose file) -- for debugging
set error_lines to {} --> collect
repeat with i from 1 to count paragraphs in log_content
if ( log_content's paragraph i contains "RC [" ) then
if ( log_content's paragraph i does not contain "RC [0]" ) then
set error_lines's end to log_content's paragraph i
end
end
end
set error_content to error_lines as string
set new_file to open for access file "MacHD:My Log" with write
permission
write error_content to new_file
close access new_file
Most of the time, it really isn't worth it to use line by line file
reading. Just give your script application a reasonable amount of
memory and read the entire file you are parsing into a variable.
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
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.