• 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: What is the best way to change the content (string of text) of a system file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the best way to change the content (string of text) of a system file?


  • Subject: Re: What is the best way to change the content (string of text) of a system file?
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 9 Mar 2006 12:28:15 -0500

On 3/9/06, Bernardo Höhl <email@hidden> wrote:
> I have used "echo" applescript's original "write to file", but I
> wonder if I could use an Unix command to find for a string of text
> and replace it, inside a system file.

In UNIXland there are a variety of ways of doing this, depending on
exactly what you're looking for and how you're deciding what to change
it to.

If you're looking for a unique string (that only appears once in the
file) and just replacing the entire thing with something else, the
traditional mechaism is to use sed into a new file and then copy the
new file in place of the original.  The more modern mechanism is to
use perl -i, which does an in-place edit of the file, so no temporary
file or renaming is required.  Thus:

sed -e 's/old string/new string/' filename >file.tmp; mv file.tmp filename

or

perl -pi -e 's/old string/new string/' filename


If you want to save a backup of the file as it existed before your
change - always a good idea - you can cp it first, or let Perl do it
for you by giving a suffix as an argument to the -i option:

perl -pi.bak -e 's/old string/new string/' filename

The above command will make a copy of 'filename' called 'filename.bak'
before applying the change to it.

--
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:

This email sent to email@hidden

References: 
 >What is the best way to change the content (string of text) of a system file? (From: Bernardo Höhl <email@hidden>)

  • Prev by Date: Re: What is the best way to change the content (string of text) of a system file?
  • Next by Date: Re: What is the best way to change the content (string of text) of a system file?
  • Previous by thread: Re: What is the best way to change the content (string of text) of a system file?
  • Next by thread: Simple Script Request
  • Index(es):
    • Date
    • Thread