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

The PERILS of using SED in Applescript.


  • Subject: The PERILS of using SED in Applescript.
  • From: "Zavatone, Alex" <email@hidden>
  • Date: Wed, 03 Aug 2011 09:35:11 -0700
  • Acceptlanguage: en-US
  • Thread-topic: The PERILS of using SED in Applescript.

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

  • Follow-Ups:
    • Re: The PERILS of using SED in Applescript.
      • From: "Mark J. Reed" <email@hidden>
    • Re: The PERILS of using SED in Applescript. Le solution!
      • From: "Zavatone, Alex" <email@hidden>
  • Prev by Date: Re: Two Monitors
  • Next by Date: Re: The PERILS of using SED in Applescript. Le solution!
  • Previous by thread: Re: Two Monitors
  • Next by thread: Re: The PERILS of using SED in Applescript. Le solution!
  • Index(es):
    • Date
    • Thread