• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: replace text in chunks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: replace text in chunks


  • Subject: Re: replace text in chunks
  • From: Laine Lee <email@hidden>
  • Date: Tue, 17 Dec 2002 12:55:55 -0600

Thanks!

BTW, this seems to work pretty well in OS X 10.2 if you don't mind writing
temp files.

Let me know if you can think of other characters that need escaping!


set search_string to text returned of ,
(display dialog "Text to search for:" default answer "search")
set replacement_string to text returned of ,
(display dialog "Text to replace it with:" default answer "replace")

set this_item to ,
(choose file with prompt "Choose your victim - a text file:")
set my_th to this_item as string

set the_sed_o to POSIX path of my_th as string

set search_r to replace_chars(search_string, "
", "
")
set search_r to replace_chars(search_string, " ", "\\ ")
set search_r to replace_chars(search_string, "/", "\\/")

set replacement_r to replace_chars(replacement_string, "
", "
")
set replacement_r to replace_chars(replacement_string, " ", "\\ ")
set replacement_r to replace_chars(replacement_string, "/", "\\/")

set theInfo to info for alias my_th
set the_name to name of theInfo

set out_er to "/private/tmp/com.mycompany.findrep." & the_name

do shell script "sed \"s/" & search_r & "/" & replacement_r & ,
"/g\"" & space & "\"" & the_sed_o & "\"" & ,
space & ">" & "\"" & out_er & "\""

do shell script "cp" & space & "\"" & out_er & "\"" & ,
space & "\"" & the_sed_o & "\""

do shell script "rm" & space & "\"" & out_er & "\""


on replace_chars(this_text, bahad, goohood)
set AppleScript's text item delimiters to the bahad
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the goohood as string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars



>
> set endChunk to startChunk + ((count search_string)* 4000)
>
> I see write out of memory about 1.5MB
>

--
Laine Lee
email@hidden
http://www.txdirect.net/users/llee
_______________________________________________
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.

References: 
 >Re: replace text in chunks (From: Andy Wylie <email@hidden>)

  • Prev by Date: Re: Replacing a character/word
  • Next by Date: RE: more news from the front
  • Previous by thread: Re: replace text in chunks
  • Next by thread: Keychain Scripting
  • Index(es):
    • Date
    • Thread