Re: [SLUG] Need help with a sed script

From: btt@nethouse.com
Date: Sat Aug 02 2003 - 11:48:21 EDT


On Sat, Aug 02, 2003 at 09:56:35AM -0400, Russ Wright wrote:
> Hey all
> I have a simple script to perform a find and replace for me. Currently it
> looks for "<?" and replaces it with "<?php".
>
> for fl in *.php; do
> mv $fl $fl.old
> sed 's/<? /<?php /g' $fl.old > $fl
> rm -f $fl.old
> done
>
> Works pretty well.
>
> However I need to make it a little smarter. I need the script to find any of
> the following "<? ", "<?=", "<?(carriage return)" and replace it with
> <?php. However it must not replace "<?php" with "<?phpphp".

This seems to work:

$ perl -p -i'.orig' -e 's/\<\?[^\s]*(\s)/\<?php\1/g' *.php

It wants to replace <? and anything after it including the first
whitespace it finds with <?php and whatever whitespace it found. I
think that should do it. It will make little backups of each file
appending '.orig' to each one in case this thing runs amok :)

Good luck!
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 15:55:37 EDT