Terminal: batch find/replace a text string in various .plist files?

I'm wondering if anyone knows how I could batch find/replace a text string in various .plist files? Here's my problem — I'm moving a directory and within that directory there are an unknown amount of references to a group name within various .plist files. These .plist files are in various sub-folders and sub-folders of these sub-folders from the root of this directory on down. There is a text string in many of these .plist files that I need to replace with a new text string and I'm wondering if anyone knows of a way via Terminal to run a command to find/replace all the instances of this text string without having to manually search out all the .plist files, then search and replace this string within these .plist files.

Basically, I'd need to run some sort of recursive find/replace on all .plist files.
I have no idea how to do this, or even if it's possible, but if it was, I'd be a HUGE help!!!

Thanks,
Kristin.

20" Intel iMac 2.16 Ghz, 12" PowerBook G4 1.33 Ghz, Power Mac G4 667 Mhz, Mac OS X (10.5.6), Xserves (Early 2009, Early 2008, G5), Mac Pro

Posted on May 11, 2009 12:13 PM

Reply
3 replies

May 11, 2009 1:15 PM in response to kristin.

It's entirely possible to do. There are even multiple ways of doing it.

One option would be via find. Something like (untested):

find /path/to/start -type f -name "*.plist" -exec sed -i -e 's/SEARCH/REPLACE/g' \;


Replace SEARCH and REPLACE with the search and replace strings, respectively.

This should work by first running a find command, starting at /path/to/start which looks for any .plist file it finds (find is, by default, recursive, so it will find all .plists in al subdirectories, too). Then for each found file it executes the sed command which does the search-and-replace work.

May 11, 2009 4:03 PM in response to Camelot

depending on the type of plist files these are, you may need to convert them first with a

plutil -convert xml1 /path/to/file.plist


i also like to edit the files in place with sed while keeping the original as a backup. the -i will do that like so:


sed -e 's/stuff/things/g' -i .`date +%Y%m%d` /path/to/file.plist


that gives you a date stamped backup of the original.

as camelot says, you can do it a bunch of ways.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Terminal: batch find/replace a text string in various .plist files?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.