• 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: The PERILS of using SED in Applescript.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The PERILS of using SED in Applescript.


  • Subject: Re: The PERILS of using SED in Applescript.
  • From: "Mark J. Reed" <email@hidden>
  • Date: Wed, 03 Aug 2011 13:01:36 -0400

Sed has nothing to do with it; consider this:

$ cat echo.as
set my_string to "hello\r\nthere\r\nma'am\r\n"
do shell script "echo " & (quoted form of ("cat <<<" & (quoted form of
my_string)))

$ osascript echo.as | od -c

0000000    c   a   t       <   <   <   '   h   e   l   l   o  \r   t   h
0000020    e   r   e  \r   m   a   '   \   '   '   a   m  \r   '  \n
0000037

Apparently, if you have any LF sequences in your string, you can't
expect it to survive the transition to 'do shell script' unmolested.
I recall seeing something similar before, but I can't remember the
details.



On Wed, Aug 3, 2011 at 12:35 PM, Zavatone, Alex
<email@hidden> wrote:
> Unless I am smoking crack, I think I have found a problem with using
> multiple sed shell commands in Applescript.
> Whenever I make one sed call, the second one never works.
> This has been boggling my mind for a while now.
> What appears to be happening is that sed is taking a string where each line
> is delimited by \r\n and only returning \r as the line delimiter.
> As far as I know, I'm not asking sed to do that.
> I've tested two sed shell calls in the Script Debugger and in the AS editor
> in Snow Leopard and this is what I get.  The AS editor actually displays the
> hidden characters properly.
> do shell script "sed 's/^  *//'<<<'?SYMBOLS\r\n?HEADING \"RSA57000 - CUSTOM
> PRICING PRODUCT MAINTENANCE\"\r\n\r\n IDENTIFICATION DIVISION.\r\n\r\n
> --> "?SYMBOLS\r?HEADING \"RSA57000 - CUSTOM PRICING PRODUCT
> MAINTENANCE\"\r\rIDENTIFICATION DIVISION.\r\rPROGRAM
> and
> do shell script "sed '/^\\*/d'<<< '?SYMBOLS\r\n?HEADING \"RSA57000 - CUSTOM
> PRICING PRODUCT MAINTENANCE\"\r\n\r\n
> --> "?SYMBOLS\r?HEADING \"RSA57000 - CUSTOM PRICING PRODUCT
> MAINTENANCE\"\r\r IDENTIFICATION DIVISION.\r\r
>
>
>
> As we can see, the \r\n, return linefeed characters are being replaced with
> just \r.
> What this means is that your first sed command will work, but the resulting
> string has its line delimiter pattern changed.  From what I have been told,
> sed requires \r\n as the pattern for determining that a line ends. This
> means that your second sed call through the shell from AppleScript will
> always fail, resulting in much confusion.
> Any input into this matter in the line of "force sed output called from a
> shell script in AppleScript to not mess with the linefeeds or force a \r\n
> pattern" will be greatly appreciated and I will speak well of your ilk to
> visiting dignitaries from foreign and obscure realms.
> TIA,
> - Alex Zavatone
>
> This email message and any attachments are for the sole use of the intended
> recipient(s) and may contain information that is proprietary to U.S.
> Foodservice, Inc and/or its subsidiaries or otherwise confidential or
> legally privileged. If you have received this message in error, please
> notify the sender by reply, and delete all copies of this message and any
> attachments. If you are the intended recipient you may use the information
> contained in this message and any files attached to this message only as
> authorized by U.S. Foodservice. Files attached to this message may only be
> transmitted using secure systems and appropriate means of encryption, and
> must be secured using the same level password and security protection with
> which the file was provided to you. Any unauthorized use, dissemination or
> disclosure of this message or it's attachments is strictly prohibited.
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
>



--
Mark J. Reed <email@hidden>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >The PERILS of using SED in Applescript. (From: "Zavatone, Alex" <email@hidden>)

  • Prev by Date: Re: The PERILS of using SED in Applescript. Le solution!
  • Next by Date: Re: Detecting a keydown or key up.
  • Previous by thread: Re: The PERILS of using SED in Applescript. Le solution!
  • Next by thread: AUTO: Dr. Bernd Wild ist nicht erreichbar (returning 24.08.2011)
  • Index(es):
    • Date
    • Thread