PHP and Sed for String Substitution

I needed to replace a string in several thousand files scattered all over the filesystem on one of our servers. I used find to create a list of files that needed to be changed, along with their complete path and called it “list.txt”. It looked something like this:


/path/to/file/one/fileone.html
/path/to/file/two/filetwo.php
/path/to/file/three/filethree.htm
/path/to/directory with spaces/filefour.txt
and so on...

I worked out the “sed” command to do the in place editing, and Zach helped me whip up a quick PHP script to read the contents of “list.txt” into an array and iterate through it. He was also nice enough to show me how to use “str_replace” to escape any annoying spaces that happened to find their way into the names of directories.

  1. < ?php
  2. $files=file('list.txt');
  3.         foreach($files as $file)
  4.         {
  5.         $command='/bin/sed -i \'s/old-string/new-string/g\' '.str_replace(' ','\ ',$file);
  6.         exec($command);
  7.         }
  8. ?>

It’s a handy little script that I’m sure I will find a use for later, so I thought I would put it up here.

Little Known CLARiiON Facts and Trivia

I’ve just returned from EMC training in MA, where we learned a wealth of information about how to use the array, but also some interesting background information about the device itself.

First, the name CLARiiON has some interesting history. Before EMC was EMC, it was Data General, who had a 16-bit minicomputer called the NOVA. DG later came up with new product which the engineers had named the NOVAII. The marketing group, not wanting to recycle the “NOVA” name, insisted that a new name be chosen. The engineers, always wanting to get their way in the end, came up with a anagram “AViiON” by reversing the letters, and cleverly placing the two “ii’s” in the middle. The CLARiiON is simply a derivative of this naming convention.

Secondly, most people know that the operating system of the CLARiiON is called “FLARE”, but it is not commonly known that this is actually an acronyms that stands for Fibre Logic Array Runtime Environment.

It is also fairly common knowledge that one can access “Engineering Mode” on a CLARiiON by pressing Ctl,shft, and f12 and entering the password “messner”. The story behind this password, however, is that the engineering group at the time were avid mountain climbers and chose the password in honor of Reinhold Messner, the first person to climb Everest without the use of oxygen. Apparently the password before that was “pink floyd”, but the marketing group didn’t approve and made them change it.