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

Re: Unix Find/Replace (Was: [OT] Shell scripting (2))


  • Subject: Re: Unix Find/Replace (Was: [OT] Shell scripting (2))
  • From: "Jonathan Levi, M.D." <email@hidden>
  • Date: Sun, 28 Dec 2003 10:33:21 -0500

On Sat, 27 Dec 2003 20:36:53 -0500, "Marc K. Myers" <email@hidden> wrote:

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.

Seems to me that a good, scriptable Unix answer would be sed (stream editor):

sed -e 's/myfindstring/myreplacestring/g' myfile

This version (not to be automated yet) will print the substituted version of myfile on the terminal. If it looks OK, you can write

sed -e 's/myfindstring/myreplacestring/g' myfile > /tmp/myfile; mv /tmp/myfile myfile

(Simply doing sed [...] < myfile > myfile will erase myfile before it gets processed, I believe.)

Finally, you can put an AppleScript wrapper around this:

do shell script "sed [...]"

Jonathan
--
_______________________________________________
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: New AppleScript book
  • Next by Date: Re: check a process
  • Previous by thread: Re: ScriptingAdditions not found - SOLVED!
  • Next by thread: Re: Unix Find/Replace (Was: [OT] Shell scripting (2))
  • Index(es):
    • Date
    • Thread