We help IT Professionals succeed at work.

Simple question

myuen asked
I'm doing some web stuff on this one linux server (running RH7).  Unfortunately, there is one line of text that is common to quite a few pages and I want to change all occurrences of that one word to something else.  For example:

Change hello.htm to hello2.htm

Is there a command that will do that for me?

Watch Question

You could use sed to change the lines. Something like:

cat mypage.html | sed -e s/hello\.htm/hello2\.htm/ > mynewpage.html

You can put that in a script with the file names as parameters, then you could call the scripte using find for all of the files, like:
find . -name *.html -exec myscript.sh {} \;

myscript.sh would look something like:

#make backup of file
cp -f $1 $1.bak
#make changes an pipe to a temp file
cat $1 | sed -e s/hello\.htm/hello2\.htm/ > /tmp/tempreplace
#copy the temp file back
cp -f /tmp/tempreplace $1
#delete the temp file
rm -f /tmp/tempreplace


I haven't tried any of this, so mock up a couple files, and try it with those before you jump into your real stuff.  Good luck. BD

Hello myuen,  BlackDiamond had noticed you had accidentally duplicated your question two times, and notified Community Support.  

I have refunded a total of 100 points back into your account, and deleted the duplicated questions. (Usually caused by using the Browsers refresh button)

Thanks to both and regards,
Community Support Moderator


Sweet Candy!


Explore More ContentExplore courses, solutions, and other research materials related to this topic.