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 Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Search and Replace in Ksh DeepakXavier Shell Programming and Scripting 9 05-28-2007 08:11 AM
sed search and replace d__browne UNIX for Dummies Questions & Answers 7 04-26-2006 09:46 AM
Search and replace sed or tr bridgeje Shell Programming and Scripting 6 10-28-2003 07:54 AM
search and Replace mukeshannamalai UNIX for Advanced & Expert Users 4 09-14-2001 06:21 AM

Closed Thread
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 04-17-2007
dannyd dannyd is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 20
search and replace

I have a I need to replace all instances of the word mysite.com to maysite.net within the public_html web folder. How can I accomplish this.
  #2 (permalink)  
Old 04-17-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
dannyd, try this:
Code:
for FileName in `ls -1`
do
 sed 's/mysite.com/mysite.net/g' $FileName > $$TempFile
 mv $$TempFile $FileName
done
  #3 (permalink)  
Old 04-17-2007
dannyd dannyd is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 20
Would this replace the keyword mysite.com to mysite.net in all subfolders as well ?
  #4 (permalink)  
Old 04-17-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Quote:
Would this replace the keyword mysite.com to mysite.net in all subfolders as well ?
No. You didn't specify it in your request.
To list all files in your directory and sub-directories, replace
`ls -1` by `find .`
  #5 (permalink)  
Old 04-17-2007
dannyd dannyd is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 20
Sorry I dont think i was clear in my question. I would like to replace all instances of the word mysite.com to mysite.net inside every file in the entire website.

I think your solution searches for files with the name mysite.com and renames them to mysite.net.
  #6 (permalink)  
Old 04-17-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
No dannyd,
My solution with the "find" loops thru every single file in the current directory
and sub-directories and for each file found, it searches and replaces the string
"mysite.com" to "mysite.net".
  #7 (permalink)  
Old 04-17-2007
dannyd dannyd is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 20
Sorry im not too experienced in unix.

Can this command be done on the command line or do i need to put this in a shell script ?
Sponsored Links
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 10:55 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