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 > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Directory inside directory problem namishtiwari Shell Programming and Scripting 6 01-27-2008 04:07 AM
replacing a number with random variable inside shell script user_prady Shell Programming and Scripting 3 09-11-2007 02:44 AM
Replacing text chrchcol Shell Programming and Scripting 3 07-25-2006 12:30 PM
replacing text ajaya Shell Programming and Scripting 2 04-12-2006 12:31 PM
Directory list inside a directory little_jhon UNIX for Dummies Questions & Answers 6 01-14-2006 01:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2006
vatsan vatsan is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 1
Replacing text inside a directory

This is my first post to this group.I am new to Unix.I have one requirement

I need to replace a text in all the files in a directory and sub-directory.Eg i have a folder structure like /usr/local/abc , inside abc i have several directories and several files. All the files inside abc and all the files inside sub-directories of abc has the text 'usr/local/def' hard coded. I need to replace the 'usr/local/def to usr/local/ghi. This needs to be repalced for all the files and files of subdirectories in abc.

Can someone help me out here?

Thanks
  #2 (permalink)  
Old 04-01-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Use the find command to get the files under the /usr/local/abc directory and use sed or ex to replace text.

Something like:
Code:
for filename in $(find /usr/local/abc -type f); do
   sed 's/usr\/local\/def/usr\/local\/ghi/' $filename > $filename.mod;
   # mv $filename.mod $filename  ## unhash this after a test run to ensure that text replacement has happened as required
done
-- NOT TESTED.
Closed Thread

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 07:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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