Subscribe to The Webmaster        RSS Feed
-----

Find & Replace

Icon 3 Comments
As you may know, last weekend I moved dream.in.code to a new server. There are hundreds of files from multiple applications that have been combined to create "dream.in.code". Each one of these applications has links, paths, and other information that is server specific. In addition to changing paths, we also changed from sub-domains to sub-folders, so all the links had to be changed to reflect the new file structure.

There isn't a super easy way in RHEL (Red Hat Enterprise) to do a find and replace across multiple files, and even harder to do it recursively, but thanks to Gabe Anderson, I was able to make light work of all those paths and URLs:
for fl in *.php; do
mv $fl $fl.old
sed 's/FINDSTRING/REPLACESTRING/g' $fl.old > $fl
rm -f $fl.old
done


You can find this, and the recursive script here:
http://www.gabeander...tiple_files.php

3 Comments On This Entry

Page 1 of 1

rockstar_ Icon

08 November 2006 - 10:30 AM
skyhawk-

When I write any web stuff for myself or others, I make it easily migratable by creating a config file with all of those paths as variables. Then include that in each page, and call the variables from within that page. It makes it a lot easier to make changes to new servers. Granted it doesn't sound like dream.in.code moves too much, but it's a thought. sed is great, but sometimes I've seen some wierd output come out of it (probably more because I'm a sed idiot...thank God for version control...)

rockstar_
0

skyhawk133 Icon

08 November 2006 - 10:36 AM
rockstar_,

I agree, and we do use the hell out of the config file I've created, but some of the applications (like InvisionBoard, Resources, and Code Snippets) are seperate applications that have been integrated in to dream.in.code. They have their own files.

On the early versions of d.i.c, there were thousands of hard coded paths. Now I'm down to about 30-45.

Now I'm working on making all the links relative instead of absolute. The old sub-domain linking structure made it tough to have relative links, but now I can clean everything up a little.
0

rockstar_ Icon

08 November 2006 - 01:18 PM

skyhawk133, on 8 Nov, 2006 - 10:36 AM, said:

I agree, and we do use the hell out of the config file I've created, but some of the applications (like InvisionBoard, Resources, and Code Snippets) are seperate applications that have been integrated in to dream.in.code. They have their own files.

Ah, the third party woes. I understand that completely! I wish there was a way to manage those third party apps better. I use an RTE for my personal CMS, and I get the wierdest behavior in some edge case urls. The pathing seems to get really messed up. Go figure.
0
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

Recent Entries

August 2014

S M T W T F S
     12
3456789
10111213141516
17181920212223
2425262728 29 30
31