Using "sed" to update RECURSIVELY a value within a directory in a Red Hat Machine

Hi All,

I spent the whole morning trying to create a shell script ( using "sed" command ) that looks for a value in a directory and its sub directory than changes it with another value but couldn't find the way :frowning:

a first step, allowded me to trace all the files that contain it and even change this value but not into the file but on the standard output ( the screen ), here after the command :

grep -R 10.220.22.240 * | grep 8080 | sed 's/10\.220\.22\.240/localhost/g'

RESULT ON SCREEN ( here after a single line for exemple ):

papers-papers.htm:        <li><a href="http://localhost:8080/display/Jd/Publications+in+2007">2007</a></li>

Now, what i'am attempting to do, is to change the value "10.220.22.240" with "localhost" INTO ALL THESE FILES !!!

i made this script below but i shoul be missing something :

===========================

#!/bin/ksh

grep -R 10.220.22.240 * | grep 8080 > ListaFile

   for a in ListaFile
    do
       sed 's/10\.220\.22\.240/localhost/g' < a > b
   
==========

one of the line included in "ListaFile", gives :

==============

testo/nav-up.htm_al13gen09:<td width="82" bgcolor="#6699CC"><div align="center"><a href="http://10.220.22.240:8080/dashboard.action" target="content" class="menu" on        Click="MM_showHideLayers('comm','','hide','description','','hide','board','','hide','application','','hide','papers','','hide','news','','hide','wiki','','show')" >        wiki</a></div></td>

==============

Can you help please ? thanx

Perl might be easier...

find . -type f -print0 | xargs -0 perl -pi -e 's/10\.220\.22\.240/localhost/g'

Thank you so much, i tried it AND IT WORKS, THATS GREAT :slight_smile: