• 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: [OT] Shell scripting (2)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] Shell scripting (2)


  • Subject: Re: [OT] Shell scripting (2)
  • From: John Fowler <email@hidden>
  • Date: Sun, 28 Dec 2003 01:21:23 -0600

> Could someone point me in the right direction as to how to do a find
> and replace on files in the Unix shell? What I'm doing now is reading
> the file into a variable, using a TID handler to find and replace, and
> writing the contents back to the file. Since this is such a common
> need there is probably a much easier way to do it via shell scripting.

I have been trying to learn related skills. Try the following. It is
a work-in-progress and a use-at-own-risk handler:

on perlreplace(inputstring, targetstring, replacementstring)
set shellscript to "/usr/bin/perl -e '$rpl=q|" & replacementstring &
"|;$thisvar=q{" & inputstring & "};$thisvar=~s/" & targetstring &
"/$rpl/sg;print $thisvar;'"
log shellscript
set theResult to (do shell script shellscript)
return theResult
end perlreplace

Good luck.

PS I don't think it's off topic.

John Fowler
_______________________________________________
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.

  • Prev by Date: RE: file name manipulation
  • Next by Date: AppleScript and CF/NS Notifications
  • Previous by thread: Re: [OT] Shell scripting (2)
  • Next by thread: RE: [OT] Shell scripting (2)
  • Index(es):
    • Date
    • Thread