• 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: do shell script "perl... " to find/replace in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: do shell script "perl... " to find/replace in a string


  • Subject: Re: do shell script "perl... " to find/replace in a string
  • From: Joseph Weaks <email@hidden>
  • Date: Thu, 18 Mar 2004 09:28:50 -0600

Chris,
Thank you, thank you, thank you thank you thank you.

When I try the AppleScript constant method, it works fine until the the base letter goes beyond standard Latin letters. (I'm working with Greek letters), which then produces unexpected results.
But the perl example using Perl's Unicode escapes is working perfectly so far.
Did I say thank you?
Joe

On Mar 18, 2004, at 4:11 AM, Christopher Nebel wrote:
Something like that. Plus, you really can use Unicode constants in AppleScript, but it's annoying:

set f to "aa"
set r to +data utxt00650301;
set s to "blah blaah blaah blah"
do shell script "echo " & quoted form of s & " | perl -pe 's/" & f & "/" & r & "/g'"
--> "blah blih blih blah" (though the e-acutes probably won't survive the list server...)

(This particular form also works with sed; just substitute "sed -e" for the "perl -pe".) Alternatively, use Perl's Unicode escapes:

set f to "aa"
set r to "\\x{0065}\\x{0301}"
set s to "blah blaah blaah blah"
do shell script "echo " & quoted form of s & " | perl -pe 's/" & f & "/" & r & "/g'"
--> "blah blih blih blah" (same thing)

...which also answers your question about replacing with a combining character sequence. The search string is case-sensitive by default; use Perl and add an "i" at the end, right after (or right before) the "g". (sed can't do this.) Bear in mind that AppleScript can't display some Unicode strings correctly, so don't freak out if it doesn't look right in the result window. Write the data out to a file or some such; it's correct.


--Chris Nebel
AppleScript Engineering
_______________________________________________
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.
_______________________________________________
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: 
 >do shell script "perl... " to find/replace in a string (From: Joseph Weaks <email@hidden>)
 >Re: do shell script "perl... " to find/replace in a string (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: do shell script and prompts
  • Next by Date: Re: osascript and Modification Date of Compiled Script
  • Previous by thread: Re: do shell script "perl... " to find/replace in a string
  • Next by thread: UI script fails when run from Mail.app's script menu
  • Index(es):
    • Date
    • Thread