Visit Our UNIX and Linux User Community

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

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using "sed" to update RECURSIVELY a value within a directory in a Red Hat Machine
# 1  
Old 07-02-2009
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 Smilie

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 * | 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 "" with "localhost" INTO ALL THESE FILES !!!

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



grep -R * | grep 8080 > ListaFile

   for a in ListaFile
       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="" 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..
# 2  
Old 07-02-2009
Perl might be easier...

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

# 3  
Old 07-02-2009
Thank you so much, i tried it AND IT WORKS, THATS GREAT Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #94
Difficulty: Easy
The mv command in Linux moves a file from one location to another, but only in the same directory.
True or False?

7 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. UNIX for Dummies Questions & Answers

how to know if i use "Red Hat Enterprise Linux" or "Red Hat Desktop" ?

how to know if i use "Red Hat Enterprise Linux" or "Red Hat Desktop" ? (2 Replies)
Discussion started by: ahmedamer12
2 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Programming

How to do a "sed-like" update command in mysql?

Dear mates, imagine a table with only one column and 10 rows containing 5 and 5 email addressess. How could I... (2 Replies)
Discussion started by: pseudocoder
2 Replies

5. Red Hat

"ERROR : failed to mount nfs source" Red Hat Kickstart

Hi There, I have been googling for this error and try solution provided but still not avail to resolve Kickstart Issue. Any expert have encounter this problem? Thanks. Regards, Regmaster (4 Replies)
Discussion started by: regmaster
4 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. Red Hat

"SCRYPT" command in RED HAT 9

Hello, I wanted to simple command to encrypt a file. Using google I got a command "crypt". I could test it very well on Sun solaris. My red hat system says "command not found".Can you please tell me if I can find that package on the cd!!! (2 Replies)
Discussion started by: nsharath
2 Replies

Featured Tech Videos