Search replace hostname in htm files

Need assistance in changing the hostname

I have multiple html files in a directory , its src is pointing to

houston.sp.com

and it needs to change to

alaska.sp.com

. Below is the example

Trying to use perl to change it . Need suggestiong

<img border="0" src="http://houston.sp.com/weather/webpages/city.list/images/ABE.gif" width="820" height="750"></p>

Need to be changed to

<img border="0" src="http://alaska.sp.com/weather/webpages/city.list/images/ABE.gif" width="820" height="750"></p>

Try

sed 's/houston\.sp\.com/alaska.sp.com/' file
1 Like

Found other way . This will change all the .htm files .

perl -i -p -e 's/old/new/g;' *.htm
find . -maxdepth 1 -type f -name '*.htm' | \
    xargs perl -i.bak -pe 's/localhost/example.com/;

Sed can do that too :stuck_out_tongue:

sed 's/houston\.sp\.com/alaska\.sp\.com/' $(find -type f -name '*.htm')

Dont forget to add -i in front of the $(find... to actualy apply the changes.

hth