Re: [SLUG] Need help with a sed script

From: Timothy L. Jones (tim@timjones.com)
Date: Sat Aug 02 2003 - 13:45:50 EDT


When looking for a filename pattern in a deep subtree, I replace the 'for'
with a 'find | while', so 'find' does all the recursion, like this:

find . -name \*.php -print | while read fl
do
        mv $fl $fl.old
        sed 's/<? /<?php /g' $fl.old > $fl
        rm -f $fl.old
done

I would also feel better about making the 'rm' conditional upon successful
completion of 'sed' like this:

        sed 's/<? /<?php /g' $fl.old > $fl && rm -f $fl.old

Then in case of an error in sed, then 'rm' is not executed, and you will still
have your old file.

tlj

El Sáb 02 Ago 2003 01:27 PM, Dylan William Hardison escribió:
> On Saturday, August 02, 2003 at 11:48AM -0400, btt@nethouse.com wrote:
> > $ perl -p -i'.orig' -e 's/\<\?[^\s]*(\s)/\<?php\1/g' *.php
>
> [^\s] could be better written as \S,
> < does not need to be backslashed on either side,
> Using $1 instead of \1 might be better.
>
> That star (*) might be too greedy, but I'm not sure
> about that.
>
> Good one liner, all the same. :)
>
> --
> The three laws of thermodynamics:
> (1) You can't get anything without working for it.
> (2) The most you can accomplish by working is to break even.
> (3) You can only break even at absolute zero.
> -
> GPG Fingerprint=D67D 2B75 53C6 9769 30E4 D390 239F C833 F32C F6F6
> GPG KeyID=F32CF6F6
> -----------------------------------------------------------------------
> 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 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:56:29 EDT