Sponsored Content
Top Forums Shell Programming and Scripting Using "sed" to update RECURSIVELY a value within a directory in a Red Hat Machine Post 302330774 by mehdi1973 on Thursday 2nd of July 2009 08:53:38 AM
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 :

Code:
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 ):

Code:
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 :

Code:
===========================

#!/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..
 

7 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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 yahoo.de and 5 gmail.com email addressess. mail1@yahoo.de mail2@yahoo.de mail3@yahoo.de mail4@yahoo.de mail5@yahoo.de mail1@gmail.com mail2@gmail.com mail3@gmail.com mail4@gmail.com mail5@gmail.com How could I... (2 Replies)
Discussion started by: pseudocoder
2 Replies

5. 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

6. 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

7. 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
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 05:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy