Front page
Silflay Hraka?

Bigwig is a systems administrator at a public university
Hrairoo is the proprietor of a quality used bookstore
Kehaar is.
Woundwort is a professor of counseling at a private university

The Hraka RSS feed

bigwig AT

Friends of Hraka
Daily Pundit
cut on the bias
Meryl Yourish
This Blog Is Full Of Crap
Winds of Change
A Small Victory
Silent Running
Dr. Weevil
Little Green Footballs
Fragments from Floyd
The Feces Flinging Monkey
Dean's World
Little Tiny Lies
The Redsugar Muse
Natalie Solent
From the Mrs.
The Anti-Idiotarian Rottweiler
On the Third Hand
Public Nuisance
Not a Fish
Electric Venom
Skippy, The Bush Kangaroo
Common Sense and Wonder
Neither Here Nor There
The Greatest Jeneration
Ipse Dixit
Blog On the Run
Redwood Dragon
Greeblie Blog
Have A Cuppa Tea
A Dog's Life
Iberian Notes
Midwest Conservative Journal
A Voyage to Arcturus
Trojan Horseshoes
In Context
The People's Republic of Seabrook
Country Store
Blog Critics
Chicago Boyz
Hippy Hill News
Kyle Still Free Press
The Devil's Excrement
The Fat Guy
War Liberal
Assume the Position
Balloon Juice
Iron Pen In A Velvet Glove
Freedom Lives
Where Worlds Collide
Knot by Numbers
How Appealing
South Knox Bubba
Heretical Ideas
The Kitchen Cabinet
Bo Cowgill
Raving Atheist
The Short Strange Trip
Shark Blog
Ron Bailey's Weblog
Cornfield Commentary
Northwest Notes
The Blog from the Core
The Talking Dog
WTF Is It Now??
Blue Streak
Smarter Harper's Index
nikita demosthenes
Bloviating Inanities
Sneakeasy's Joint
Ravenwood's Universe
The Eleven Day Empire
World Wide Rant
All American
The Rant
The Johnny Bacardi Show
The Head Heeb
Viking Pundit
Oscar Jr. Was Here
Just Some Poor Schmuck
Katy & Bruce Loebrich
But How's The Coffee?
Roscoe Ellis
Sasha Castel
Susskins Central Dispatch
Josh Heit
Aaron's Rantblog
As I was saying...
Blog O' Dob
Dr. Frank's Blogs Of War
Betsy's Page
A Knob for Brightness
Fresh Bilge
The Politburo Diktat
Drumwaster's rants
Curt's Page
The Razor
An Unsealed Room
The Legal Bean
Helloooo chapter two!
As I Was Saying...
SkeptiLog AGOG!
Tong family blog
Vox Beth
I was thinking
Judicious Asininity
This Woman's Work
Fragrant Lotus
Single Southern Guy
Jay Solo's Verbosity
Snooze Button Dreams
You Big Mouth, You!
From the Inside looking Out
Night of the Lepus
No Watermelons Allowed
From The Inside Looking Out
Lies, Damn Lies, and Statistics
Suburban Blight
The SmarterCop
Dog of Flanders
From Behind the Wall of Sleep
Beaker's Corner
Bad State of Gruntledness
Who Tends The Fires
Granny Rant
Elegance Against Ignorance
Say What?
Blown Fuse
Wait 'til Next Year
The Pryhills
The Whomping Willow
The National Debate
The Skeptician
Zach Everson
Geekward Ho
Life in New Orleans
Rotten Miracles
The Biomes Blog
See What You Share
Blog d’Elisson
Your Philosophy Sucks
Watauga Rambler
Socialized Medicine
Verging on Pertinence
Read My Lips
The Flannel Avenger
Butch Howard's WebLog
Castle Argghhh!
Andrew Hofer
Moron Abroad
White Pebble
Darn Floor
Pajama Pundits
Goddess Training 101
A & W
Medical Madhouse
Slowly Going Sane
The Oubliette
American Future
Right Side Redux
See The Donkey
Newbie Trucker
The Right Scale
Running Scared
Ramblings Journal
Focus On Reality
Wyatt's Torch

October 23, 2003

Replacing Text in Multiple Files

Ok, I think I've finally restored Hraka, as well as FDS and The Warren, to their full functionality. The last remaining obstacle to this was the commenting function, which worked fine unless one happened to be accessing comments via one of the category archives, such as Unseen History or Demon Liquor.

Essentially what happened is once upon a time, just after I moved the site off blogspot, the url "" didn't really exist yet. For the first couple of days of the new blog's existance, anyone or anything who wanted to get here had to use the IP address Silflay had been assigned, This included the Movable Type application I was using to publish to the site. I never bothered to change it once it was no longer necessary to use the IP address, since by then "" and "" meant the same thing anyway.

But when Hosting Matters moved Silflay off of that IP address, due to the presumed jihadi DoS attacks, the site was crippled. Publishing and commenting were especially affected. At one point, before I figured out what was going on, I was having to rebuild the entire site each time I wanted to publish a new post.

A couple of config changes restored 90% of the functionality, but the last 10% was the hard part. There are over 3000 separate html and xml files on the site, and damn near every one of them had a reference to instead of somewhere in the code, usually multiple times

Now there's no way I was going to replace every single one of those instances by hand, so I started writing a shell script to do it for me. I never finished it, as I can across this Dean Mah perl script after a quick Google on multiple file text replacement.

If you need to use it, don't do a direct cut and paste of the code, at least not into a vi session. There are a couple of windows characters and some odd HTML escapes in there that will trip you up. Here's what it looked like for me once I fixed those.


# Replaces a string within multiple files
# specified on the command line

$mv = '/bin/mv';

$op = shift || die("Usage: $0 perlexpr [filenames]\n");

if (!@ARGV) {
@ARGV = ;

foreach $file (@ARGV) {
if (!-f $file) { print "Skipping non-regular file: $file\n" ;; next; }
if (-B $file) { print "Skipping binary file: $file\n"; next; }

$outfile = "/usr/tmp/$file.$$";

open(FILE, $file) || die "Couldnt open $file: $!\n" ;
undef $/;
$_ = ;

if (eval $op) {
open(OFILE, "> $outfile") || die("Couldn't open $outfile: $!\n");
print OFILE;

system($mv, '-f', $file, "$file.bak");
system($mv, '-f', $outfile, $file);

print "File changed: $file\n";
else {
print "No change to file: $file\n";


Note that a couple of paths have also changed. That's a reflection of the local quirks of the Hosting matters server I ran it on. You should also know that Hosting Matters already has a program called "replace" running on its servers, so you'll need to name the file something other than that if you want to use it on one of their boxes. I called mine "hrakareplace", calling it via the command line like this.

$ hrakareplace 's/63\.247\.131\.116/silflayhraka\.com/g' *.html

The backslashes are there to let the program know that what follows immediately afterwards is an actual period rather than a wild card that represents something else.

The "*.html" is there to let the program know to do the replacement in every file that ends in a .html extension. Make sure you have enough space on the server allocated to you before running the program with that argument! Say, at least double whatever it is at present. If you don't know, don't run it.

I can say this becuase I did not know, and ended up with a bunch of empty files where there used to be deathless prose when the program ran into the space wall at high speed. Fortunately Hosting Matters runs a nightly backup, so the Hraka archives were back up after an hour or so. The hour wait was enough to wear down the fingernails to nubs, though.

Now, I jest need someone to point out how this could have been done via the command line rather than a Perl script, and my day will be complete.

Posted by Bigwig at October 23, 2003 02:42 PM | TrackBack
First time visitor to House Hraka? Wondering if everything we produce could possibly be as brilliant/stupid/evil/pedantic/insipid/inspired as the post you just read? Check out the Hraka Essentials, the (mostly) reader-selected guide to Hraka's best posts, and decide for yourself.

But that's the prob with relying on IP addresses... really meant, not With ARIN's new restrictions dedicated IP addresses are not as easy to come by these days...we require hoop jumping and actual blood donation first.*

*No, not really.

Posted by: Stacy at October 23, 2003 02:58 PM
Post a comment Note: Comments with more than two dashes per line will be blocked as spam.

Remember personal info?