The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Mac OS X 10.5: Time Machine - "The backup volume could not be found" alert iBot OS X Support RSS 0 06-25-2009 01:15 PM
Mac OS X 10.5.3 or later: Time Machine - "Backup volume could not be mounted" after c iBot OS X Support RSS 0 10-14-2008 03:50 PM
How do I connect a hpux10.x os machine to "the internet" via a WinXP client? liumx2000 UNIX for Dummies Questions & Answers 0 08-22-2008 12:34 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
how to "remsh" from a Unix machine to a Linux or SunOS elthox UNIX for Dummies Questions & Answers 2 10-09-2007 09:22 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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 09:16 AM..
  #2 (permalink)  
Old 07-02-2009
cjcox cjcox is offline
Registered User
  
 

Join Date: May 2005
Posts: 64
Perl might be easier...

Code:
find . -type f -print0 | xargs -0 perl -pi -e 's/10\.220\.22\.240/localhost/g'
  #3 (permalink)  
Old 07-02-2009
mehdi1973 mehdi1973 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 16
Thank you so much, i tried it AND IT WORKS, THATS GREAT
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0