Re: sed replacement headscratcher
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|'|\\\\\\'|"
>
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|&|\\\\&|g;" & ,
quoted form of "s|'|\\\\\\'|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|'|\\\\'|"
>
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.