Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-20-2003, 08:31 PM   #1
LQ Newbie
Registered: Jan 2003
Posts: 1

Rep: Reputation: 0
Question Search and replace links

Hello all,
I am trying to figure out a way to search and replace text links within pages in all web folders on our server at once.

Ex: replace all instances of
with :

Any ideas? I am not local to the machine, so all work is done through remote ssh1 connect in shell.
I tride using this:

perl -pi -e "s/www\.oldsite\.com/www\.newsite\.com/g;" *.html

But, perl doesn't seem to like going recursively into directories.
Any help would be appreciated. Thanks,

Old 01-29-2003, 10:02 AM   #2
Registered: Oct 2002
Location: Curitiba - Brazil
Distribution: Conectiva
Posts: 334

Rep: Reputation: 30
Try with sed:

sed 's/' *.html

Hope that helps ...
Old 01-29-2003, 10:08 AM   #3
LQ Guru
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 68
vlad, would that work on subdirectories as well? And, would it work for things like email adresses (in the html form <a href="mailto"">Webmaster</a> and changing just the "" to "")?

Old 01-29-2003, 10:25 AM   #4
Registered: Oct 2002
Location: Curitiba - Brazil
Distribution: Conectiva
Posts: 334

Rep: Reputation: 30
I forgot something, using sed will show the result as stdout, so it's necessary to direct it to a file:

sed 's/expression/other expression/g' file > other file

So It should be easier with a shell ( could be used with email addresses too, and subdirectories ) :

# for file in `find . -iname *.html`; sed 's/' $file > $ ; done
Old 01-29-2003, 11:55 AM   #5
Registered: Sep 2002
Distribution: Slackware 8.1
Posts: 84

Rep: Reputation: 15
I did something like this once, when our webserver (at the university was reconfigured):
It's a bit more complicated than the above versions since i use vim
to do the editing.

basically the server was moved so it was accessed
instead of
the following did the trick, the www2stud file is attacked.
Grep only reduces the number of replacements done, but it can be
removed without making much of a difference.


for item in `find -name '*.html'`
echo -n "scanning ${item} ... "
repl=`egrep -c '' ${item}`
if [ $repl -ge 1 ]
echo "replacing"
`vim -e -s ${item} < ${script}`
echo "clean"



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python search and replace Accordion Programming 1 02-22-2005 07:54 PM
Batch search and replace devilkin Linux - Newbie 2 02-14-2005 02:39 AM
Emacs search and replace neil Linux - Software 1 01-28-2005 06:04 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
Grep for search, but what for replace? TheSpecial Linux - Software 18 04-28-2003 09:01 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration