AWG Blogs

Saturday, May 1, 2010

Replacing Form Action Scripts with sed

I needed to replace all form action scripts in all my XSLT templates, specifically to make the script relative to the current path. So I did:
find . -name "*.xsl" -type f -exec sed -i "s#\([\"|'|>]\)/index.php#\1index.php#g" {} \;
There are a few of things to notice about this command:

I used a double quote and not a single quote for the sed script namely because A single quote may not occur between single quotes, even when preceded by a backslash. *

The parenthesis required backslashes because sed apparently is not running in extended mode on my machine.

The argument to sed needs to be quoted to avoid being parsed by the bash shell interpreter. Aside the from the parenthesis the only other character needing escaping is the double quote in the regex. Even the \ don't need further escaping because a double quote string preserves the literal value of all characters except \, $, and `. The backslash has its special meaning only if followed by ", $, `, \, and newline. *http://answers.google.com/answers/threadview/id/496910.html

No comments:

Post a Comment