The biggest caveat in what I'm trying to do is that I have to be able to use the command line tools that are built into Mac OS X by default. This is because I want to include a script as part of an install script and would prefer not to install any extra tools, even if only temporarily.

So far it looks like the Mac OS version of sed doesn't handle replacing newlines, which has thrown a monkey wrench into this.

Here's what I want to do...

Search through an arbitrary number of files in a specific folder which contain XML content, for a specific block of text which includes tabs and newlines.

Then I want to replace that block with a new block of text, which also includes tabs and newlines.

Sample of the text I'm searching for:

Code:
			<key>Action Data</key>
			<dict>
				<key>Display Name</key>
				<string>My App</string>
				<key>Should Repeat</key>
				<false/>
				<key>Type</key>
				<integer>2</integer>
			</dict>




I thought about using AppleScript's support for plists instead, but that seems to require you to specify specific keys within which to write - this data can exist anywhere, under any parent key, so that's a dead end. A more straight-forward search and replace is what I need.

I've found a simple example of using sed for text without tabs or newlines, but I don't know how to make it work in Mac OS X because my tests of matching on a newline followed by tabs have been unsuccessful.

Reference:

http://hintsforums.macworld.com/archive/index.php/t-62778.html

So based on a comment in that thread about sed and newlines, I'm trying to use perl instead. And I can easily find tabs and I can even find a newline. But when I search for a newline followed by tabs, I'm not getting anything.

This works

Code:
perl -pe 's!\t\t\t\t<string>My App</string>\n!TEST REPLACEMENT!g'


And this doesn't (it has a tab after the newline, as I'm trying to get the first character from the next line...)

Code:
perl -pe 's!\t\t\t\t<string>My App</string>\n\t!TEST REPLACEMENT!g'



Edited by hybrid8 (14/09/2011 14:52)
_________________________
Bruno
Twisted Melon : Fine Mac OS Software