?
Solved

Replacing text with another text in a certain directory recursively using a bash script

Posted on 2005-03-16
9
Medium Priority
?
1,003 Views
Last Modified: 2010-04-21
Greetings,

I want a shell script that can replace a text with another text for special file types (*.html, for an instance) in a certain directory recursivle. The modified file has of course to be in the same location of the original file.

Thanks,
Hossam
0
Comment
Question by:mBf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 600 total points
ID: 13556029
find . -type f -name \*.html|xargs perl -i.bak -pe 's/lamb/sheep/g'
0
 

Author Comment

by:mBf
ID: 13556204
Works.
Suppose that I want to change www.domain1.com to www.domain2.com..
Would it be: find /root/test -type f -name \*.html|xargs perl -i.bak -pe 's/www.domain1.com/www.domain2.com/g' without any escape characters?

Cheers,
Hossam
0
 

Author Comment

by:mBf
ID: 13556290
Also, instead of "." should I enter the directory name as "/directory/path/" or "/directory/path/."?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 13556336
find /root/test -type f -name \*.html|xargs perl -i.bak -pe 's/www\.domain1\.com/www.domain2.com/g'
# more perfect
0
 

Author Comment

by:mBf
ID: 13556507
When I test this script it works well, but when I use it in a real life situation it does not modify the files nor produce .bak ones. Very weird!

Any suggestions?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13556581
sounds like your real life data does not match your test requirements :-))
you have to change one of them ..
0
 

Author Comment

by:mBf
ID: 13556609
Got it.. For some reason this command does not follow symlinks.
Thanks, ahoffmann and much appreciated

--Hossam
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13557354
for symlinks you have to check find's docs, symlinks, mount points and -prune are the dragons to beat on each platform :-(
0
 

Author Comment

by:mBf
ID: 13557612
Maybe on my vacation ;)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question