• 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: sed replacement headscratcher
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sed replacement headscratcher


  • Subject: Re: sed replacement headscratcher
  • From: Gnarlodious <email@hidden>
  • Date: Sat, 06 Mar 2004 23:36:40 -0700

Entity Christopher Nebel spoke thus:

> (Phew!)
Ditto on that! Thanks for the exhaustive explanation.

> You could type fewer backslashes by using single quotes around the sed
> pattern (inside single quotes, everything is literal), so then you'd
> only need three, which means AppleScript needs six:
>
> set someChars to " & ' "
> set re to "s|'|\\\\\\&#39;|"
> set cmd to "echo " & (quoted form of someChars) & " | sed " & quoted
> form of re

This escapes all characters in the string prior to running a sed
substitution:

set thisSong to do shell script "echo " & the quoted form of thisSong & "|
sed " & ,
quoted form of "s|&|\\\\&amp;|g;" & ,
quoted form of "s|'|\\\\\\&#39;|g;" & ,
quoted form of "s|/|\\\\/|g"


> Perl doesn't give "&" any special
> meaning, and has much better regular expression syntax:
>
> set someChars to " & ' "
> set re to "s|'|\\\\&#39;|"
> set cmd to "echo " & (quoted form of someChars) & " | perl -pe " &
> quoted form of re
I'll keep it in mind, thanks.

-- Gnarlie
_______________________________________________
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.


  • Follow-Ups:
    • Re: sed replacement headscratcher
      • From: Walter Ian Kaye <email@hidden>
References: 
 >Re: sed replacement headscratcher (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: The other Folder Action handlers
  • Next by Date: Re: Script for Post.Office
  • Previous by thread: Re: sed replacement headscratcher
  • Next by thread: Re: sed replacement headscratcher
  • Index(es):
    • Date
    • Thread