• 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
Getting unexpected results from sed inside AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting unexpected results from sed inside AppleScript


  • Subject: Getting unexpected results from sed inside AppleScript
  • From: James Nierodzik <email@hidden>
  • Date: Wed, 21 Nov 2007 10:56:02 -0600

I have a sample sed statement that I am running from the terminal that works just fine

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
echo '<body>
<p>This is some html with a link <a href=""http://anothersite.com/woot">http://anothersite.com/woot"><b>Restocked Traditional Items.</b></a></p>
<p>and</p>
<p>a link <a href=""http://anothersite.com/woot">http://anothersite.com/woot">over here</a></p>
</body>' | sed 's/\(<a href=""\)/\1 style="color:black"/g'
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



And when I run it I get the expected, and desired, results... The   style="color:black"    being added to both links. 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<body>
<p>This is some html with a link <a href=""http://anothersite.com/woot">http://anothersite.com/woot" style="color:black"><b>Restocked Traditional Items.</b></a></p>
<p>and</p>
<p>a link <a href=""http://anothersite.com/woot">http://anothersite.com/woot" style="color:black">over here</a></p>
</body>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



The problem though is when doing this in AppleScript.   I wrote the following

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
set theHtml to "<body>
<p>This is some html with a link <a href="" href="http://anothersite.com/woot">http://anothersite.com/woot\"><b>Restocked Traditional Items.</b></a></p>
<p>and</p>
<p>a link <a href="" href="http://anothersite.com/woot">http://anothersite.com/woot\">over here</a></p>
</body>"


set theCommand to "echo '" & theHtml & "' | sed 's/\\(<a href="" style=\"color:black\"/g'"

set fixedHtml to do shell script theCommand
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


From this looking at   theCommand  you can see the statement is being escaped properly, that is unless I'm blind, but I am getting back undesired results

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<body>
<p>This is some html with a link <a href=""http://anothersite.com/woot">http://anothersite.com/woot"><b>Restocked Traditional Items.</b></a></p>
<p>and</p>
<p>a link <a href=""http://anothersite.com/woot">http://anothersite.com/woot" style="color:black">over here</a></p>
</body>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Notice that only the second link is having the style added.  Any ideas why this may be happening?  OS: 10.5.1


Thanks in advance,

James Nierodzik


 _______________________________________________
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: Getting unexpected results from sed inside AppleScript
      • From: James Nierodzik <email@hidden>
  • Prev by Date: Re: Script fails with Leopard.
  • Next by Date: Re: Getting unexpected results from sed inside AppleScript
  • Previous by thread: Re: Script fails with Leopard.
  • Next by thread: Re: Getting unexpected results from sed inside AppleScript
  • Index(es):
    • Date
    • Thread