Bastos

let’s code!


shell script salvando o mundo

Quando vc quer achar uma string em arquivos de um diretório e trocar ela por alguma outra coisa… Bash tem a solução!

for i in `find *.php`
    do
        perl -pi -e "s/find/replace/g;" $i
    done

Substitui “find” por “replace”. Simples e lindo. Ah usa perl… Tá tá, perl foi muito bom pra fazer isso…

[update]
Usando sed, o Nicholas me mandou essa:

find . -iname \*.php -ok bash -c "sed 's/find/replace/gI' {} > tmp; mv tmp {}" \;

[/updade]

Published by Bastos, on January 24th, 2007 at 4:36 pm. Filled under: perl, shel lscript, tips | 13 Comments