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
SERVICE(8)                                                    System Manager's Manual                                                   SERVICE(8)

NAME
service - run a System V init script SYNOPSIS
service SCRIPT COMMAND [OPTIONS] service --status-all service --help | -h | --version DESCRIPTION
service runs a System V init script or systemd unit in as predictable an environment as possible, removing most environment variables and with the current working directory set to /. The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT, or the name of a systemd unit. The existence of a systemd unit of the same name as a script in /etc/init.d will cause the unit to take precedence over the init.d script. The supported val- ues of COMMAND depend on the invoked script. service passes COMMAND and OPTIONS to the init script unmodified. For systemd units, start, stop, status, and reload are passed through to their systemctl/initctl equivalents. All scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart, the script is run twice, first with the stop command, then with the start command. service --status-all runs all init scripts, in alphabetical order, with the status command. The status is [ + ] for running services, [ - ] for stopped services and [ ? ] for services without a status command. This option only calls status for sysvinit jobs. EXIT CODES
service calls the init script and returns the status returned by it. FILES
/etc/init.d The directory containing System V init scripts. /{lib,run,etc}/systemd/system The directories containing systemd units. ENVIRONMENT
LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEA- SUREMENT, LC_IDENTIFICATION, LC_ALL, TERM, PATH The only environment variables passed to the init scripts. SEE ALSO
/etc/init.d/skeleton update-rc.d(8) init(8) invoke-rc.d(8) systemctl(1) AUTHOR
Miloslav Trmac <mitr@redhat.com>, Petter Reinholdtsen <pere@hungry.com> Licence: GNU Public Licence v2 (GPLv2) COPYRIGHT
2006 Red Hat, Inc., Petter Reinholdtsen <pere@hungry.com> Jan 206 SERVICE(8)
All times are GMT -4. The time now is 01:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy