The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-02-2009
mehdi1973 mehdi1973 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 16
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

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

Last edited by mehdi1973; 07-02-2009 at 10:16 AM..